- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 4.7k
 
Closed as not planned
Closed as not planned
Copy link
Description
Describe the bug
Modifying non-trivial $state (i.e. not a number) and then reading it inside the same $effect cause an infinite loop of calls of the effect.
Reproduction
https://svelte.dev/playground/ec99f39270c6463b9162af3432c29298?version=5.34.7
This works:
<script>
	let mystate = $state(12);
	$effect(() => {
		mystate = 13;
		if(mystate == 21)
			alert("a message");
	});
</script>
<h1>{mystate}</h1>
This doesn't:
<script>
	let mystate = $state(12);
	$effect(() => {
		mystate = [];
		if(mystate == 21)
			alert("a message");
	});
</script>
<h1>{mystate}</h1>
(the difference is that I assign [] to mystate in the $effect)
Logs
Last ten effects were:  
Array(10) [ inner(), App(), inner(), App(), inner(), App(), inner(), App(), inner(), App() ]
Uncaught Svelte error: effect_update_depth_exceeded
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
https://svelte.dev/e/effect_update_depth_exceeded [srcdoc line 45 > eval:191:18](about:srcdoc line 45 > eval)System Info
Tested online on the Playground with svelte 5.34.7 and Firefox 139.0.4 on macOS 15.5Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels