You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Something is wrong with nested state and reactivity when using StateHistory
#301
I'm trying to do the most basic example work with a nested state. So I took the sample code in runed homepage (https://www.runed.dev/docs/utilities/state-history) and adapted it to be used with a nested state. According to this issue in order to make it work, I need to return a snapshot of the state in the getter, and so I did:
The only way of solving this I've found is by replacing the root state object in the update, so that svelte reactivity performs the internal_set in step 4 and when clicking the second undo (step 5), the internal_set returns false for the equal check:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I'm trying to do the most basic example work with a nested state. So I took the sample code in runed homepage (https://www.runed.dev/docs/utilities/state-history) and adapted it to be used with a nested state. According to this issue in order to make it work, I need to return a snapshot of the state in the getter, and so I did:
This code works fine in terms of doing undo/redo, but something strange happens in this scenario:
The last undo does nothing, I have to click it again and undo two steps to make it react.
After a lot of debugging, I found that after the first undo, the next increment doesn't update the internal state of the counter, so when the next undo is clicked, the svelte internal_set (https://github.com/sveltejs/svelte/blob/d2ba2589fee2ec6985c0fe0fbd800ab34518378e/packages/svelte/src/internal/client/reactivity/sources.js#L171) performs the equal check, finds that the new value is equal to the source (because it didn't get updated) and doesn't do anything, just returns the value.
The only way of solving this I've found is by replacing the root state object in the update, so that svelte reactivity performs the internal_set in step 4 and when clicking the second undo (step 5), the internal_set returns false for the equal check:
But if I implement a rather similar code (of course is not the same, is way more simple) in vanilla svelte, it works well: https://svelte.dev/playground/fc8e2da31f8d4e389c97a9f478ba85a2?version=latest
Is there something I'm missing, or is this a bug with runed StateHistory?
Thank you very much.
All reactions