diff --git a/.changeset/heavy-insects-float.md b/.changeset/heavy-insects-float.md new file mode 100644 index 000000000000..b57aa4d4f5c9 --- /dev/null +++ b/.changeset/heavy-insects-float.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: don't reassign bound imports on the server diff --git a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js index 941088228a1a..3ae6d7ff06c3 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js @@ -80,22 +80,28 @@ export function build_inline_component(node, expression, context) { const value = build_attribute_value(attribute.value, context, false, true); push_prop(b.prop('init', b.key(attribute.name), value)); } else if (attribute.type === 'BindDirective' && attribute.name !== 'this') { - // TODO this needs to turn the whole thing into a while loop because the binding could be mutated eagerly in the child push_prop( b.get(attribute.name, [ b.return(/** @type {Expression} */ (context.visit(attribute.expression))) ]) ); - push_prop( - b.set(attribute.name, [ - b.stmt( - /** @type {Expression} */ ( - context.visit(b.assignment('=', attribute.expression, b.id('$$value'))) - ) - ), - b.stmt(b.assignment('=', b.id('$$settled'), b.false)) - ]) - ); + if ( + // Don't reassign imports + attribute.expression.type !== 'Identifier' || + attribute.expression.name !== attribute.name || + context.state.scope.get(attribute.name)?.declaration_kind !== 'import' + ) { + push_prop( + b.set(attribute.name, [ + b.stmt( + /** @type {Expression} */ ( + context.visit(b.assignment('=', attribute.expression, b.id('$$value'))) + ) + ), + b.stmt(b.assignment('=', b.id('$$settled'), b.false)) + ]) + ); + } } }