-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: Deeply nested state doesn't re-render when looping #10685
Comments
Maybe #9546 is related? |
The So unless you make the items themselves reactive, you need to use access via key on the source (which is less efficient as far as I am aware). const state = $state(initialValue); // adds proxy reactivity to object
const roomState = writable(state); (The statefulness would not survive complete re-assignment, so {#each Object.values($roomState.users) as user (user.name)}
{$roomState.users[user.name].value}
{/each} |
This can't be the expected behavior for stores, this is clearly a regression that needs to be fixed. |
Some migration work can be expected when switching to runes mode, but I guess it would make sense to have special treatment for stores. Store usage is at least visible to the compiler via the |
If we were to put in special handling when we see <script>
// ..
const users = Object.values($roomState.users);
</script>
{#each users as user (user.name)}
{user.value}
{/each} Personally, this feels like a breaking change that we need to note and cover with migration notes. We can't really do a runtime check here either. |
That snippet is static because it's not using Can you elaborate why the change isn't noticed in this case? I haven't dug into it yet. |
Sorry, I meant to make it |
That's the whole idea behind stores though? Every single expression that contains
What does "without that syntax" mean? The dollar prefix is the syntax. |
It also works without the syntax in Svelte 4. |
I still don't know what syntax you're talking about :D. I assume you mean regular reactivity? Also this already works perfectly fine with I don't understand the discussion. The expression |
Yes, but that logic can be in another function too. <script>
function getPeople() {
return Object.values($roomState.users)
}
</script>
{#each getPeople() as user (user.name)}
{user.value}
{/each} |
It works with And yes, indirection complicates this matter... |
I see, not sure if anyone would expect that to work (unless you change |
Apologies if I oversimplified the original example, a slightly more complicated but hopefully more informational REPL can be found here of what I was actually doing: REPL Effectively I'm attempting to use a derived store value. Again I could totally be wrong, but the example works with the Svelte 4 compiler but not Svelte 5 unfortunately |
I think this was introduced through #10537 - strict equality checks now happen in runes mode instead of in immutable mode. I think we can add that strict equality only if we can statically determine that the state we're listening to is |
@dummdidumm I'll take a look at this tomorrow and see what we can do :) |
Additional PRs related to this:
(Fixing |
Describe the bug
It seems that when looping through a deeply nested object, svelte doesn't re-render when looping through object.
No errors are thrown in the logs which makes me think this may be a bug.
Reproduction
Repl
Click the update button and observe that the JSON.stringify correctly shows the update, but the each block isn't updated with the new value.
Note: I'm using the $inspect to force the compiler to svelte 5 mode. Without it, it works as expected.
Logs
No response
System Info
Severity
blocking all usage of svelte
The text was updated successfully, but these errors were encountered: