@@ -499,6 +499,7 @@ function build_element_spread_attributes(
499
499
is_custom_element
500
500
) {
501
501
let needs_isolation = false ;
502
+ let is_reactive = false ;
502
503
503
504
/** @type {ObjectExpression['properties'] } */
504
505
const values = [ ] ;
@@ -523,35 +524,41 @@ function build_element_spread_attributes(
523
524
values . push ( b . spread ( /** @type {Expression } */ ( context . visit ( attribute ) ) ) ) ;
524
525
}
525
526
527
+ is_reactive ||=
528
+ attribute . metadata . expression . has_state ||
529
+ // objects could contain reactive getters -> play it safe and always assume spread attributes are reactive
530
+ attribute . type === 'SpreadAttribute' ;
526
531
needs_isolation ||=
527
532
attribute . type === 'SpreadAttribute' && attribute . metadata . expression . has_call ;
528
533
}
529
534
530
- const update = b . stmt (
531
- b . assignment (
532
- '=' ,
533
- attributes_id ,
534
- b . call (
535
- '$.set_attributes' ,
536
- element_id ,
537
- attributes_id ,
538
- b . object ( values ) ,
539
- context . state . analysis . css . hash !== '' && b . literal ( context . state . analysis . css . hash ) ,
540
- preserve_attribute_case ,
541
- is_custom_element ,
542
- is_ignored ( element , 'hydration_attribute_changed' ) && b . true
543
- )
544
- )
535
+ const call = b . call (
536
+ '$.set_attributes' ,
537
+ element_id ,
538
+ is_reactive ? attributes_id : b . literal ( null ) ,
539
+ b . object ( values ) ,
540
+ context . state . analysis . css . hash !== '' && b . literal ( context . state . analysis . css . hash ) ,
541
+ preserve_attribute_case ,
542
+ is_custom_element ,
543
+ is_ignored ( element , 'hydration_attribute_changed' ) && b . true
545
544
) ;
546
545
547
- context . state . init . push ( b . let ( attributes_id ) ) ;
546
+ if ( is_reactive ) {
547
+ context . state . init . push ( b . let ( attributes_id ) ) ;
548
+
549
+ const update = b . stmt ( b . assignment ( '=' , attributes_id , call ) ) ;
550
+
551
+ if ( needs_isolation ) {
552
+ context . state . init . push ( build_update ( update ) ) ;
553
+ return false ;
554
+ }
548
555
549
- // objects could contain reactive getters -> play it safe and always assume spread attributes are reactive
550
- if ( needs_isolation ) {
551
- context . state . init . push ( build_update ( update ) ) ;
552
- } else {
553
556
context . state . update . push ( update ) ;
557
+ return true ;
554
558
}
559
+
560
+ context . state . init . push ( b . stmt ( call ) ) ;
561
+ return false ;
555
562
}
556
563
557
564
/**
0 commit comments