Skip to content

Crash on circular reference assignment in $state with 5.34.0+ #16620

@rhiller

Description

@rhiller

Describe the bug

Assigning a circular reference into a $state object immediately crashes with a RangeError (maximum call stack size exceeded) in Svelte 5.34.0+, even without any recursion.

This worked as expected in Svelte 5.33.19.

Reproduction

<script>
  const filesState = $state({ files: {} });
  let nodes = { id: 1, items: [{ id: 2, items: [{ id: 3 }, { id: 4 }] }] };

  filesState.files = nodes;
  console.log('before assignment');
  filesState.files.items[0].parent = filesState.files; // 💥 crashes here
  console.log('after assignment'); // never reached
</script>

Logs

System Info

- Svelte version: 5.34.0 (and above)
- Previous working: 5.33.19

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions