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 migration: erroneous $state declaration when each block present #12169

Closed
Rich-Harris opened this issue Jun 24, 2024 · 1 comment
Closed
Labels
Milestone

Comments

@Rich-Harris
Copy link
Member

Rich-Harris commented Jun 24, 2024

Describe the bug

This...

<script>
  const { foo } = x();
</script>

{#each foo as f}{/each}

...gets turned into this by the migrator:

<script lang="ts">
  const { foo } = $state(x());
</script>

{#each foo as f}{/each}

There's no reason for this to be state.

Reproduction

demo

@Rich-Harris Rich-Harris modified the milestones: 6.0, 5.0 Jun 24, 2024
@dummdidumm
Copy link
Member

The problem isn't the migration, it's the analysis phase who falsely gives the variable the state kind. If you look at the output in legacy mode you see that it creates a mutable source.

dummdidumm added a commit that referenced this issue Jul 11, 2024
This enhances our "variable was mutated" detection to also recognize that `foo` in `[foo[1]] = [..]` was mutated. This allows us to be more granular about detecting mutations to each expressions in legacy mode, which fixes #12169
trueadm pushed a commit that referenced this issue Jul 16, 2024
…roach) (#12429)

This enhances our "variable was mutated" detection to also recognize that `foo` in `[foo[1]] = [..]` was mutated. This allows us to be more granular about detecting mutations to each expressions in legacy mode, which fixes #12169

---------

Co-authored-by: Simon Holthausen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants