-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Team,
I have a setup where I'm processing data in a sequence / nesting of Sweet State containers, where the result (i.e., state) of one container is passed into the next container as a prop. In terms of data processing, this "sequence" is more of a directed graph, looking like e.g. this:
... meaning that the output of Alpha is used both in Beta, where it causes an update to Gamma and ultimately Delta, and also in Delta directly.
In React 17, as well as with defaults.batchUpdates = false, this works "synchronously" (for the lack of a better word), meaning that when Alpha updates, Delta updates only once, with the updated Alpha value and the updated Gamma value.
In React 18, the same setup causes Alpha to update twice, first with the updated Alpha value and the old Gamma value, and then with both values updated.
See this reproduced here: https://codesandbox.io/p/devbox/sweet-state-batching-issue-2kpdyx?file=%2Fsrc%2FApp.tsx%3A14%2C34. Open the console, and hit "Update". (The problem doesn't seem to happen on initial render.)
Mille grazie!