Skip to content

Infinite recursion in $effect #15568

Closed as not planned
Closed as not planned
@elpres

Description

@elpres

Describe the bug

The effect in the following code is looping indefinitely:

<script>
	let x = $state(0);
	let y = $state({a: 0});
	$effect(() => setY(x));

	function setY(newX){
		y = {a: 1};
		console.log($state.snapshot(y));
	};
</script>

Converting the first line in the function to y.a = 1 fixes the problem. Commenting out the second line (the one with console.log
) also does.

Reproduction

REPL

Logs

System Info

Tested with Svelte 5.22.5 (locally) and 5.23.2 (REPL)

Severity

blocking all usage of svelte

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions