-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the bug
A deep state rune that is accessed in an onDestroy of a component and that is updated in same tick as removing the component will provide old value even to non reactive code directly accessing the state object, same with untrack and snapshot. The js assumption of synchronous reasonable order of write/read operations is broken making it impossible to reason about order of state updates. The documentation mentions that reactivity would not be ensured in situations like this which would require eager but eager is also not working for data changes in same tick as on destroy, making ugly hacks for cleanup that depends on state needed and the documentation mentions nothing about state being frozen internally and runes providing outdated data to different access contexts.
This also hints at an implementation that copy state data around instead of using js objects that behave as users expect, which would hint at a plethora of similar possible bugs.
Reproduction
https://svelte.dev/playground/49d503ea86854196b5f928f202761f1d?version=5.46.0
Logs
value in change method: changed
value in comp destroy: init value
value in comp destroy, snapshot: init value
value in comp destroy, untrack: init valueSystem Info
version=5.46.0Severity
severe, as this is easy to fix with an await tick(), but to know misbehaviour is present in the first place and find the bug is near impossible as fundamental mental model how objects work in js is broken.