'Watch()' permanently stops reacting after changes during an intial async action. #1183
RichardsA25
started this conversation in
General
Replies: 2 comments
-
|
Hi, thanks for opening a discussion. Could you try https://github.com/valtiojs/valtio-reactive ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
#924 is a related discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm not an expert, but...
Bug
watch()permanently stops reacting after changes during an intial async action (e.g. AsyncStorage).Especially prominent with nested arrays.
Root cause
watch()uses a global mutablecurrentCleanupsvariable.subscribe()(called inside the callback) queues its first notification viaPromise.resolve().then().Doing an async modification to the main proxy somehow causes parallel revalidate commands for
watch(), causing the external currentCleanups to equal something not right, andwatchends up deleting it's own subscription.Raw
subscribe()works fine (no global state).Could be a similar race condition problem in
derive-valtiothat other's have posted about.Fix
Remove the global and make nesting local to each
watchinstance:Beta Was this translation helpful? Give feedback.
All reactions