-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
zustand does not behave properly with useLayoutEffect #276
Comments
Nice catch. I'd say it's not a desired behavior, but it's the expected behavior from the current implementation. Line 83 in a4307f3
It subscribes in useEffect and to mitigate when it's changed before subscription it checks at L105.
To fix this behavior, we'd need to change this useEffect to useLayoutEffect, but I'm not sure if it's worth it. Note this behavior is only for the mount time, once subscription is made, useLayoutEffect should work properly, I suppose. |
Thank you! |
Hm, in one of my libs, I used LayoutEffect as there's no other choices. useSubscription from react team uses passive Effect intentionally. Maybe because it doesn't know the cost of Finally, react-redux uses LayoutEffect. As we know subscribe in zustand is pretty lightweight, we can change it to useIsomorphicLayoutEffect. (It would be obsoleted in v4-experimental #160 anyway.) Anyone wants to open a PR? (Preferably with a test) |
I'm working on it right now 🤗 |
IMO this codesandbox should not blink a red page
https://codesandbox.io/s/sad-currying-wwrm8
Is it an expected behavior?
The text was updated successfully, but these errors were encountered: