Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5: legacy $: behaves differently #15251

Open
zeroberry opened this issue Feb 9, 2025 · 0 comments
Open

Svelte 5: legacy $: behaves differently #15251

zeroberry opened this issue Feb 9, 2025 · 0 comments

Comments

@zeroberry
Copy link

zeroberry commented Feb 9, 2025

Describe the bug

In Svelte 5 legacy reactive $: also runs before onMount if its dependency state is updated in the child component initialization. (via default value or assignment)
I think relying on this behavior is a bad practice, but it could be a breaking change.

<script>
	import { onMount } from 'svelte'
	import Component from "./Component.svelte"
	
	let foo;

	onMount(() => {
		foo = false;
	})

	$: if (foo) {
		// This now runs in svelte 5
		console.log('reactive: ', foo);
	}
</script>

<Component bind:foo />
<!-- Component.svelte -->
<script>
	export let foo = true;
</script>

Reproduction

Same code in Svelte 4 and Svelte 5 playgrounds:

Logs

System Info

-

Severity

blocking an upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant