Skip to content
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

Open
kshutkin opened this issue Apr 2, 2022 · 3 comments
Open

[store] Adopt useSyncExternalStore for @slimlib/store #5

kshutkin opened this issue Apr 2, 2022 · 3 comments
Assignees

Comments

@kshutkin
Copy link
Owner

kshutkin commented Apr 2, 2022

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.

@kshutkin
Copy link
Owner Author

kshutkin commented Apr 2, 2022

@kshutkin
Copy link
Owner Author

kshutkin commented Jun 17, 2022

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.

@kshutkin
Copy link
Owner Author

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.

@kshutkin kshutkin closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2022
@kshutkin kshutkin self-assigned this Jun 19, 2022
@kshutkin kshutkin added the wontfix This will not be worked on label Jun 19, 2022
@kshutkin kshutkin reopened this Oct 15, 2022
@kshutkin kshutkin removed the wontfix This will not be worked on label Oct 15, 2022
@kshutkin kshutkin changed the title Adopt useSyncExternalStore for @slimlib/store [store] Adopt useSyncExternalStore for @slimlib/store Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant