@@ -27,7 +27,7 @@ export function build_set_attributes(
27
27
is_custom_element
28
28
) {
29
29
let needs_isolation = false ;
30
- let is_reactive = false ;
30
+ let has_state = false ;
31
31
32
32
/** @type {ObjectExpression['properties'] } */
33
33
const values = [ ] ;
@@ -38,8 +38,7 @@ export function build_set_attributes(
38
38
39
39
if (
40
40
is_event_attribute ( attribute ) &&
41
- ( get_attribute_expression ( attribute ) . type === 'ArrowFunctionExpression' ||
42
- get_attribute_expression ( attribute ) . type === 'FunctionExpression' )
41
+ ( value . type === 'ArrowFunctionExpression' || value . type === 'FunctionExpression' )
43
42
) {
44
43
// Give the event handler a stable ID so it isn't removed and readded on every update
45
44
const id = context . state . scope . generate ( 'event_handler' ) ;
@@ -48,30 +47,30 @@ export function build_set_attributes(
48
47
} else {
49
48
values . push ( b . init ( attribute . name , value ) ) ;
50
49
}
50
+
51
+ has_state ||= attribute . metadata . expression . has_state ;
51
52
} else {
52
53
values . push ( b . spread ( /** @type {Expression } */ ( context . visit ( attribute ) ) ) ) ;
53
- }
54
54
55
- is_reactive ||=
56
- attribute . metadata . expression . has_state ||
57
55
// objects could contain reactive getters -> play it safe and always assume spread attributes are reactive
58
- attribute . type === 'SpreadAttribute' ;
59
- needs_isolation ||=
60
- attribute . type === 'SpreadAttribute' && attribute . metadata . expression . has_call ;
56
+ has_state = true ;
57
+
58
+ needs_isolation ||= attribute . metadata . expression . has_call ;
59
+ }
61
60
}
62
61
63
62
const call = b . call (
64
63
'$.set_attributes' ,
65
64
element_id ,
66
- is_reactive ? attributes_id : b . literal ( null ) ,
65
+ has_state ? attributes_id : b . literal ( null ) ,
67
66
b . object ( values ) ,
68
67
context . state . analysis . css . hash !== '' && b . literal ( context . state . analysis . css . hash ) ,
69
68
preserve_attribute_case ,
70
69
is_custom_element ,
71
70
is_ignored ( element , 'hydration_attribute_changed' ) && b . true
72
71
) ;
73
72
74
- if ( is_reactive ) {
73
+ if ( has_state ) {
75
74
context . state . init . push ( b . let ( attributes_id ) ) ;
76
75
77
76
const update = b . stmt ( b . assignment ( '=' , attributes_id , call ) ) ;
0 commit comments