Skip to content

Svelte 5: Logging a proxy in an $effect causes it to fire on any mutation #13285

Closed
@brunnerh

Description

@brunnerh

Describe the bug

In #13142 logic was added that snapshots state proxies for logging.
The state is deeply evaluated without untrack which can lead to different $effect behavior in dev.

(Promoted my comment to an issue so it's not lost)

Reproduction

<script>
	let count = $state({ value: 0 });

	function increment() {
		count.value += 1;
	}

	$effect(() => {
		console.log('triggered on mutation', count);
	});
	
	$effect(() => {
		count;
		console.log('not triggered on mutation');
	});
</script>

<button onclick={increment}>
	clicks: {count.value}
</button>
<button onclick={() => count = { value: 0 }}>
	Reset via object assignment
</button>

REPL

Logs

No response

System Info

REPL

Severity

annoyance

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