Skip to content

Commit ae5fdf9

Browse files
committed
Improve compiler output on legacy components to prevent infinite loops from <select> bind:value on $: (block) with derived variable
1 parent 5c70fa5 commit ae5fdf9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,20 @@ function setup_select_synchronization(value_binding, context) {
414414
bound = /** @type {Identifier | MemberExpression} */ (bound.object);
415415
}
416416

417-
// guard against reactively-derived bindings to prevent circular dependencies
417+
// Skip synchronisation if the bound identifier is *already* updated by a
418+
// reactive statement (declared directly in `$:` or assigned inside one).
419+
// In those cases the extra invalidate-helper would re-write its own
420+
// source signal and create a circular update loop.
418421
if (bound.type === 'Identifier') {
419422
const binding = context.state.scope.get(bound.name);
420-
if (binding && binding.kind === 'legacy_reactive') {
421-
// skip synchronization for reactive-derived bindings,
422-
// the reactive statement already handles updates properly
423-
return;
423+
if (binding) {
424+
// 1) declared directly inside a `$:`
425+
if (binding.kind === 'legacy_reactive') return;
426+
427+
// 2) declared elsewhere but *assigned* inside a `$:` block
428+
for (const [, rs] of context.state.analysis.reactive_statements) {
429+
if (rs.assignments.has(binding)) return;
430+
}
424431
}
425432
}
426433

0 commit comments

Comments
 (0)