-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
{#each}
block overwrites objects in state array
#10387
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
Comments
Turns out using a keyed each block fixes this issue, as documented here: https://learn.svelte.dev/tutorial/keyed-each-blocks I'd still argue that this should be considered a bug, as not properly updating the DOM is one thing, but overwriting objects in state still seems unintended to me. I will leave this issue open for the time being. |
This is definetly a bug, the array shouldn't get mutated here. Svelte 5 REPL reproduction |
I think I stumbled upon the same bug and made another reproduction sample for my usecase:
|
These issues should be resolved now. |
fixed by #10422 |
Describe the bug
First off: I'm not entirely sure this is a bug, so if I'm just misunderstanding some intended behaviour here, please let me know.
The
src/routes/+page.svelte
file in the reproduction repo contains a heavily simplified version of some state logic I've written in a project of mine. The rough breakdown of the setup is as follows:strat
state is an object, which contains an array ofsteps
. The demo contains 3 objects insteps
.step
contains two arrays:players
andstickies
view
state is an object with a single number value:activeStep
{#each}
block, iterating overstrat.steps[view.activeStep].players
view.activeStep
to 0, 1, or 2 respectivelyA possibly important note: The repro I've provided shows no issues in [email protected] and below. The issue starts appearing at version 5.0.0-next.18.
The presence of this
{#each}
block alone - nothing else is being done anywhere - leads to some very peculiar behaviour. First off, some definitions: I will be referring to the step active on page load as "initial step", and the one targeted byview.activeStep
as "current step".players
of the step being activated overwrite those found in the initial step. (The demo only contains a singleplayer
object for brevity, but if there are more, all objects in the array get overwritten).activePlayer.fromStep
output in the "UI".{#each}
block tostickies
instead, you will observe the exact same behaviour, but with thestickies
objects, instead.I hope this was a decent description of the issue I encountered. Let me know if there are any questions.
Reproduction
https://stackblitz.com/~/github.com/marc-eggers/svelte-5-bug-repro
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: