-
Notifications
You must be signed in to change notification settings - Fork 49.8k
Description
Steps To Reproduce
- schedule two updates using "default priority" scope (eg. from within setTimeout)
- let one of the updates be handled through
useSyncExternalStoreand let the other one be handled through regularsetState
Link to code example:
https://codesandbox.io/s/interesting-chatterjee-9ed8hj?file=/src/App.js (without unstable_batchedUpdates)
https://codesandbox.io/s/prod-glitter-51vwm1?file=/src/App.js (with unstable_batchedUpdates)
The current behavior
The useSyncExternalStore update gets flushed and committed before the other one has a chance to be committed to the screen. This doesn't allow me to read the updated state of the committed DOM of the children components from within the Parent's effect
The expected behavior
I would expect to be able to "join" this sync update of the useSyncExternalStore somehow. Ideally, I wouldn't have to wrap both with unstable_batchedUpdates. It would be cool if I could just schedule a single update with the same priority. If I understand correctly multiple updates coming from different useSyncExternalStore updates can be batched together (it doesn't work like flushSync, so it doesn't literally immediately flush the scheduled update) - and I would just like to hop on that train with my second update.
I could live with the solution based on unstable_batchedUpdates but that doesn't seem to work either.