•5 min read

React Maximum Update Depth Exceeded: It Counts Commits, Not Renders

The dashboard had been eating a CPU core for eleven days before anyone noticed. It was an internal page only I opened, and the fan announced the problem before I checked anything else. Nine hundred requests to /api/metrics in about a minute, the network panel scrolling like a slot machine. Sentry was empty and the console stayed quiet.

If you have ever gone looking for a fix for "Maximum update depth exceeded", you know the message. What took me a while to accept is that the error is a courtesy, not a guarantee. React only reports the loops it manages to catch, and mine was one it never caught.

Black metal spiral staircase against a sunlit wall

What the limit actually counts

Eventually I opened the react-dom 19.3.1 source and read it. Three separate limits live in there, and they are not the same thing.

NESTED_UPDATE_LIMIT is 50. When a commit schedules another update on the same root, React bumps a counter, and once that counter passes 50 it throws. The wording of that throw mentions componentWillUpdate and componentDidUpdate, which tells you how old that branch is.

NESTED_PASSIVE_UPDATE_LIMIT is also 50, and it guards updates scheduled from useEffect. This is the part most write-ups skip. When that counter trips, React resets it and calls console.error. It does not throw. In the code I read, an effect-driven loop is a log line, and you get roughly one of them per fifty wasted cycles.

The third limit, RE_RENDER_LIMIT, is 25. It covers something else entirely: setState called during render, where React re-runs the same component body in place. Different counter, different message: the one about too many re-renders. Several posts I read tangled all three together, which is how people end up adding useMemo to a component that never had an identity problem.

Why my loop stayed silent

The counter is not a render count. It counts consecutive commits where the previous commit scheduled a new update. A commit that schedules nothing resets it to zero.

That one sentence explains the whole eleven days. My effect awaited a fetch. The state update landed in a later task, after React had committed and moved on, so the counter never accumulated. The loop was real, it just kept breaking its own chain before anyone could count it. Eleven days at fifteen requests a second is a billing conversation I would rather not have had.

Here is the code that did it. range is a fresh object on every render, so the dependency never compares equal:

function SpendChart({ accountId, from, to }) {
  const [rows, setRows] = useState([]);
  const range = { from, to }; // new object, every render

  useEffect(() => {
    fetchMetrics(accountId, range).then(setRows);
  }, [accountId, range]); // never stable

  return <Chart data={rows} />;
}

Then came the refactor that finally produced an error. I added a clamp step that wrote the range back into state synchronously, before the fetch. No await, no gap, so the update landed inside the commit cycle and the counter climbed. The page threw on mount and I have never been so relieved to see a stack trace.

That is the trap. The async version of a loop hides itself. Take the await out and the same bug becomes loud.

The fix is usually subtraction

Almost every loop I have written came from copying a value into state to use it elsewhere. Build it where it is used instead, and depend on primitives:

function SpendChart({ accountId, from, to }) {
  const [rows, setRows] = useState([]);

  useEffect(() => {
    let cancelled = false;
    fetchMetrics(accountId, { from, to }).then((next) => {
      if (!cancelled) setRows(next);
    });
    return () => {
      cancelled = true;
    };
  }, [accountId, from, to]); // primitives only

  return <Chart data={rows} />;
}

The object now gets built inside the effect, where nothing watches its identity. Three primitives replace one object that churned on every render, and the effect runs when the inputs actually change.

When the loop is legitimate

Some loops are genuine synchronization, where a refetch really should replace the rows. A polling timer will do it, and so will two components writing the same state. For those, bail out of the render instead of trying to prevent the update:

// next is the rows you just fetched
setRows((prev) => (sameIds(prev, next) ? prev : next));

Returning the previous reference makes React skip the re-render. The effect still fires and the request still goes out, but the browser stops painting work nobody can see. It buys you time to find the real source.

Two more shapes worth knowing fail with different text. A useSyncExternalStore subscription whose getSnapshot returns a new object logs "The result of getSnapshot should be cached to avoid an infinite loop". A measuring ref callback that sets state will loop too, because an inline arrow ref is a new function on every render and React detaches and reattaches it. Same disease, different symptom.

How to catch one in under a minute

Do not wait for the error. Open the network panel first, sorted by count. A page that should fetch once per interaction but shows forty identical requests is looping, whether or not React says anything. I run that check before reading code now. It takes seconds and never lies.

If the requests look clean, drop console.count into the component body and watch it climb while the page sits idle. Strict Mode will double a loop, which is why I now stop the dev server, run a production build, and reproduce there before I trust a number. And when the error does appear, read the component stack before reaching for useMemo. The loop is nearly always in the effect that owns the setter, not in the component that re-rendered.

My corrected version of that effect and the one-line bailout guard now live in my snippet library, mostly so I stop retyping them at 1am. That is what Snippet Ark is for. The fan is quiet again, which is the only metric I actually trust.