Replies: 1 comment
-
|
Thanks for raising it up. We can't simply migrate, but our plan is to add the uSES version in the next major. Stay tuned and please be patient. |
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.
-
Hey everyone 👋
I'd like to propose migrating Jotai's React bindings from the current
useReducer+useEffectpattern to React'suseSyncExternalStoreAPI. This change would better align Jotai with React 18+ best practices and resolve potential issues in concurrent rendering — especially state tearing.🎯 Why?
Currently,
useAtomValueusesuseReduceranduseEffectto subscribe to atom updates:While functional, this approach can lead to tearing in concurrent mode — where different components may read inconsistent values during the same render pass. This violates React's principle of consistency for external state.
React officially recommends
useSyncExternalStorefor libraries managing external state because it:getServerSnapshot🚀 Proposed Change
Replace the current subscription logic with
useSyncExternalStore:We'd use the official shim to ensure compatibility with React 17.
✅ Benefits
getServerSnapshotdelayoption may need to be redesigned or deprecated (it was designed for debouncing re-renders, butuseSyncExternalStoredelivers updates synchronously).🤔 Open Questions
I'd love your input on:
delayoption? If so, how should it work with synchronous updates?🙋 Call for Feedback
Please share your thoughts:
📚 References
P.S. I'm happy to implement this change if the team agrees on the direction. 🛠️
Thanks for reading — looking forward to your feedback! 🙏
Beta Was this translation helpful? Give feedback.
All reactions