-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: {#each expression as name (key)}
behaves differently than Svelte 4
#11232
Comments
{#each expression as name (key)}
behaves differently than Svelte 4
It doesn't happen in the production build, it probably has something to do with HMR |
Yes, I can confirm this, which may explain why the issue is not reproduced in |
Can you really use the value itself as a key? I've always thought it was not at all expected but it may be a relic from my Vue days since it isn't mentioned in the docs. Anyway if you |
Yes you can
|
Yes although I have trouble seeing what's the under the hood difference in this case VS not using at all a key? Since the keys should also be modified along the values? Worth noting that both repros work as expected without key. |
No, I tried that version and it produces the same effect. I can adapt this to a new reproduction of that syntax if you need it. Here you go: |
I haven't figured out why, exactly, but this is related to HMR — if I disable it in the Vite config, things work as expected. That's why you can't reproduce it in the REPL |
Describe the bug
{#each expression as name (key)}...{/each}
The issue is that the behavior of
key
in the above syntax is different in Svelte 4 and 5.It took a lot of time to lock in to this and make an intuitive minimal reproduction.
Strangely, somehow it couldn't be reproduced in the official
Svelte5-REPL
, so I had to useStackBlitz
to provide an online preview.You can see in the demo how the actual rendering of the component elements behaves differently when changing the order of the array elements.
Reproduction
StackBlitz-svelte-4.2.15
StackBlitz-svelte-5.0.0-next.108
Svelte5-REPL (Unable to reproduce)
svelte5.0.0-next.108.mp4
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: