Bug: flushSync on component having useLayoutEffect in some cases causes Maximum update depth exceeded #27613
Labels
Resolution: Stale
Automatically closed due to inactivity
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
React version: 18.2.0
Steps To Reproduce
Click me
in the code example.Link to code example: https://codesandbox.io/s/infallible-joana-ysrxxt?file=/src/App.js
The current behavior
It fails with
Maximum update depth exceeded
message.The expected behavior
It should stabilize after few (2-4) re-renders, it definitely should not fail.
What seems to be happenning:
complexState
is scheduled (but not yet processed) on row marked as R2.complexState
is performed, leading to state update, but of different state hook -counter
state.counter
state and does not trigger the layout effect (effect depending oncomplexState
). Alas, it seems to re-run the state-updater from R3 (again!), which then leads to triggerring the layout effect again and hence the loop.counter
update in layout effect would follow.What I think is wrong is the re-applying of R3 state-updater in step 4 after layout effect (I think this state update should be considered as already committed). I don't know the React codebase much so the issue might be something else, e.g. maybe the
counter
state update in the layout effect gets applied to wrong committed state (as if it started off from the state that was there before user clicked the button, and React tries to apply accumulated changes, i.e. R3 +counter
update?).Other notes:
The text was updated successfully, but these errors were encountered: