Skip to content

Svelte 5: Store auto-subscriptions cause inconsistent variable shadowing. #11144

Closed
@brunnerh

Description

@brunnerh

Describe the bug

This is a bit of a corner case:
If there is a variable shadowing a (top-level) store, this will either result in an error or not depending on whether an auto-subscription has been created elsewhere.

Reproduction

<script>
	import { writable } from 'svelte/store';
	const user = writable(0);
	const users = [];
	$: selected = users.find(user => user.id == $user);

	// Remove to get error:
	$: console.log($user);
</script>

Svelte 5
Svelte 4 - Always errors as I would have expected

Logs

No response

System Info

REPL - Svelte v5.0.0-next.100

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