Skip to content

Svelte 5: compilation error when referencing shadowed state #13314

Closed
@trueadm

Description

@trueadm

Describe the bug

Given this use test case:

<script>
  const { count } = $props();

  let local = $derived.by(() => {
    const local = $state({ count })

    return local;
  });
</script>

<div>Local: {local.count}</div>

You can see the compiled output for the return local is incorrectly return $.get(local); This is because we are shadowing the local binding.

This means that we then push the state object into the dependencies for the derived signal causing everything to crash to a halt.

Reproduction

Repro case

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions