Skip to content

Commit 0d38498

Browse files
committed
unify
1 parent 9bae34c commit 0d38498

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

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

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ function build_element_spread_attributes(
499499
is_custom_element
500500
) {
501501
let needs_isolation = false;
502+
let is_reactive = false;
502503

503504
/** @type {ObjectExpression['properties']} */
504505
const values = [];
@@ -523,35 +524,41 @@ function build_element_spread_attributes(
523524
values.push(b.spread(/** @type {Expression} */ (context.visit(attribute))));
524525
}
525526

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';
526531
needs_isolation ||=
527532
attribute.type === 'SpreadAttribute' && attribute.metadata.expression.has_call;
528533
}
529534

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
545544
);
546545

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+
}
548555

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 {
553556
context.state.update.push(update);
557+
return true;
554558
}
559+
560+
context.state.init.push(b.stmt(call));
561+
return false;
555562
}
556563

557564
/**

0 commit comments

Comments
 (0)