-
Notifications
You must be signed in to change notification settings - Fork 0
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
[store] Adopt useSyncExternalStore for @slimlib/store #5
Comments
Looks like React comparing snapshots using Object.is. In my implementation if callback is called than store is changed and because it is always the same underlying object Object.is is always true and React never re-renders component. If I try to deep clone or just clone object on each getSnapshot it does not work either as React re-rendering component in infinite loop. So next solution will be to only clone after callback called. This means that to support useSyncExternalStore we need a lot of additional logic and memory allocation so probably it needs more experimentation/performance testing. |
After some experiments I'm not convinced that supporting useSyncExternalStore helps with tearing with this specific store implementation. I've tried solution from my previous comment and it works but according to tests https://github.com/dai-shi/will-this-react-global-state-work-in-concurrent-rendering/ I still have the same cases failed. More or less it is probably because despite the fact that we have sync getSnapshot the store itself is not sync but works through microtask. Generally it helps to defer update to less busy time when microtask resolved but it hurts if we want more granular timeslicing. So far it should be closed as Won't fix but can be reconsidered later if better approach proposed. |
To prevent tearing adopt useSyncExternalStore for @slimlib/store. Take a look how it works with other stores and how and if it is possible with fully mutable approach.
The text was updated successfully, but these errors were encountered: