Repository navigation
Backlog
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug
Description
Update: See #38428 (comment)
React version: 19.3.1 (works fine in 18.3.1)
Steps To Reproduce
- Render 30 rows like the ones below.
- Load each row's data once, each in its own
setTimeout(0). This is what TanStack Query does when it notifies queries.
function Placeholder() {
const [visible, setVisible] = useState(true);
useEffect(() => {
setVisible(true); // already true
}, []);
return visible ? <span>…</span> : null;
}
function Content({ store, onStatusChange }) {
const loaded = useSyncExternalStore(store.subscribe, store.getSnapshot);
useLayoutEffect(() => {
if (loaded) onStatusChange('loaded');
}, [loaded, onStatusChange]);
return loaded ? <b>content</b> : null;
}
function Row({ store }) {
const [, setStatus] = useState('loading');
return (
<div>
<Content store={store} onStatusChange={setStatus} />
<Placeholder />
</div>
);
}
stores.forEach((store) => setTimeout(() => store.load(), 0));We hit this in a table with a Base UI avatar and one query per row.
The current behavior
React throws "Maximum update depth exceeded", but nothing is actually looping. Each row's store changes once, which means two commits per row. With 30 rows that's 60 commits, which is just over the limit of 50.
It goes away if I:
- switch to React 18.3.1,
- remove the
setVisible(true), or - load all rows in the same task.
The expected behavior
No error, same as in React 18.
Notes
Here's what claude thinks is going on:
setVisible(true)bails out, but the update stays in the queue.- When the layout effect triggers a sync re-render, that leftover update gets skipped, and
DefaultLanestays pending on the root (ReactFiberHooks.js#L1429). - The nested update check counts a commit whenever any
SyncUpdateLanesare still pending, even ones that commit didn't schedule (ReactFiberWorkLoop.js#L4284-L4293). The next row's timer fires before the leftover work gets a chance to render, so the count keeps climbing from row to row. - React 18 only counted a pending
SyncLane, which would explain why 18.3.1 is fine. Maybe the check could only count lanes that were scheduled during that commit?
Related reports
Other libraries seem to be running into the same thing:
- Base UI's Autocomplete throws when you type fast, from a same-value
setStatein an effect (mui/base-ui#5994). - Material UI's TextField and Popper throw for the same reason, and also work fine on 18.3.1 (mui/material-ui#49701). They've worked around it on their side (#49703).
- react-admin throws on list pages with one react-query query per row, with a stack going through
useSyncExternalStore(marmelab/react-admin#11392).
Metadata
Metadata
Assignees
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug
Activity
[-]Bug: "Maximum update depth exceeded" without an update loop, after a same-value setState[/-][+]Bug: "Maximum update depth exceeded" when unrelated updates arrive in separate tasks[/+]phibr0 commentedon Nov 28, 2026
I looked into this further and the title was too narrow: the same-value
setStateisn't required. I've renamed the issue.Simpler repro
No same-value update, no layout effect. 60 rows, each store loaded in its own
setTimeout(0):This throws "Maximum update depth exceeded" on the 53rd row. Each row updates exactly once.
What is actually going on
The nested update counter goes up after every commit that leaves
SyncLane,InputContinuousLaneorDefaultLanework pending, and it only goes back to zero after a commit that leaves none:react/packages/react-reconciler/src/ReactFiberWorkLoop.js
Lines 4285 to 4293 in edae846
DefaultLanework pending. In the repro above it is the update from the passive effect; in my original repro it was the skipped same-value update.So commits from unrelated updates add up as if they were one cascade. Nothing resets the counter between independent tasks.
Corrections to my original notes
SyncLane. The check was widened toSyncLane | InputContinuousLane | DefaultLanein Bugfix: Selective hydration triggers false update loop error #27439.I have a fix with tests and will open a PR. (#38429)