Skip to content

Commit 77f90a7

Browse files
committed
merge
2 parents 18cef80 + bc2d30c commit 77f90a7

File tree

1 file changed

+10
-11
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/visitors/shared

1 file changed

+10
-11
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/element.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function build_set_attributes(
2727
is_custom_element
2828
) {
2929
let needs_isolation = false;
30-
let is_reactive = false;
30+
let has_state = false;
3131

3232
/** @type {ObjectExpression['properties']} */
3333
const values = [];
@@ -38,8 +38,7 @@ export function build_set_attributes(
3838

3939
if (
4040
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')
4342
) {
4443
// Give the event handler a stable ID so it isn't removed and readded on every update
4544
const id = context.state.scope.generate('event_handler');
@@ -48,30 +47,30 @@ export function build_set_attributes(
4847
} else {
4948
values.push(b.init(attribute.name, value));
5049
}
50+
51+
has_state ||= attribute.metadata.expression.has_state;
5152
} else {
5253
values.push(b.spread(/** @type {Expression} */ (context.visit(attribute))));
53-
}
5454

55-
is_reactive ||=
56-
attribute.metadata.expression.has_state ||
5755
// 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+
}
6160
}
6261

6362
const call = b.call(
6463
'$.set_attributes',
6564
element_id,
66-
is_reactive ? attributes_id : b.literal(null),
65+
has_state ? attributes_id : b.literal(null),
6766
b.object(values),
6867
context.state.analysis.css.hash !== '' && b.literal(context.state.analysis.css.hash),
6968
preserve_attribute_case,
7069
is_custom_element,
7170
is_ignored(element, 'hydration_attribute_changed') && b.true
7271
);
7372

74-
if (is_reactive) {
73+
if (has_state) {
7574
context.state.init.push(b.let(attributes_id));
7675

7776
const update = b.stmt(b.assignment('=', attributes_id, call));

0 commit comments

Comments
 (0)