Improve compiler output on legacy components to prevent infinite loops from <select> bind:value on $: (block) with derived variable

pull/16165/head
raythurnvoid 3 months ago
parent d3fe49548a
commit c411d0c4f5

@ -414,13 +414,20 @@ function setup_select_synchronization(value_binding, context) {
bound = /** @type {Identifier | MemberExpression} */ (bound.object); bound = /** @type {Identifier | MemberExpression} */ (bound.object);
} }
// guard against reactively-derived bindings to prevent circular dependencies // Skip synchronisation if the bound identifier is *already* updated by a
// reactive statement (declared directly in `$:` or assigned inside one).
// In those cases the extra invalidate-helper would re-write its own
// source signal and create a circular update loop.
if (bound.type === 'Identifier') { if (bound.type === 'Identifier') {
const binding = context.state.scope.get(bound.name); const binding = context.state.scope.get(bound.name);
if (binding && binding.kind === 'legacy_reactive') { if (binding) {
// skip synchronization for reactive-derived bindings, // 1) declared directly inside a `$:`
// the reactive statement already handles updates properly if (binding.kind === 'legacy_reactive') return;
return;
// 2) declared elsewhere but *assigned* inside a `$:` block
for (const [, rs] of context.state.analysis.reactive_statements) {
if (rs.assignments.has(binding)) return;
}
} }
} }

Loading…
Cancel
Save