Closed brunnerh closed 4 months ago
Thanks for this fix!
The simple test case is resolved by #10128, but I'm still seeing infinite loops in my library against 5.0.0-next.31
. It seems like the loops are coming from existence checks in reactive statements.
Here's a slightly more complex test case with an existence check to only update the object's members if the object itself is defined:
<script>
// Button object is initially undefined
let button;
let title = '';
let label = '';
// Simulate button becoming defined
// (In practice, this would be be set elsewhere, e.g by a wrapped vanilla JS library)
button = { label: 'foo', title: 'bar' };
// Reactive statements need to check for button's existence before setting keys
// works fine in Svelte 4, `ERR_SVELTE_TOO_MANY_UPDATES` in Svelte 5
$: button && (button.title = title);
$: button && (button.label = label);
$: console.log(button);
</script>
Svelte 5 REPL vs Svelte 4 REPL
It seems like maybe button
is firing a reactive event on the object when its members change, even if the identity of the object itself is unchanged.
Given REPL now works.
Describe the bug
When setting a property on an object in a reactive statement, the object becomes a dependency. This can easily cause infinite loop issues if multiple such statements exist, breaking compatibility with v4.
(Found by @kitschpatrol, relevant to svelte-tweakpane-ui)
Reproduction
REPL
Generated code:
Note the
button
dependency that is being added.Same code in v4: REPL
Logs
System Info
Severity
blocking an upgrade