You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've run in a strange issue where an $effect seems triggered by a parent component's state change when it shouldn't be causing it to go into an infinite loop and throwing an ERR_SVELTE_TOO_MANY_UPDATES: Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops.
This works as expected, although it's tricky at first to understand why. The reason is that items[id] is a read which is becoming a signal dependency to the effect. Because items[id] is undefined initially and after doing the assignment it's true, it's firing an update event immediately. That causes the effect to rerun, which means the cleanup function is called which sets it back to undefined, and so it happens over and over again.
For one-off stuff like this it's probably easier to use onMount instead.
Describe the bug
I've run in a strange issue where an
$effect
seems triggered by a parent component's state change when it shouldn't be causing it to go into an infinite loop and throwing anERR_SVELTE_TOO_MANY_UPDATES: Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops.
Reproduction
Link to REPL
Parent component:
Child component:
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: