0
Challenge · 89React Internals

Commit Phase

Internalsused in ~40% of apps

The render phase (#88) is pure and produces nothing you can see — it just computes a diff. The commit phase is where React actually touches the real DOM: it applies that diff, attaches refs, runs layout effects, then passive effects. If you have ever wondered exactly when the screen changes and when useEffect fires, this is the answer.

Core idea. After render computes the minimal set of changes, the commit phase synchronously applies them to the real DOM, then attaches refs and runs layout effects before the browser paints, and finally runs passive effects (useEffect) asynchronously after paint.
Playground, this isn't a screenshot
commit pipeline (top → bottom, in order)
the real DOM node
<div class="like">
<span>0</span>
</div>
ref = null
what the user sees
Like · 0
not painted yet
effects
useLayoutEffectsync
useEffectasync
Render output (from #88). The render phase finished: a new element tree plus a computed diff — “the <span> text goes 0 → 1”. Nothing on screen has changed yet. The commit phase takes this diff as its input.

The render phase can pause and restart; the commit phase runs start to finish, synchronously — steps 2–3 cannot be interrupted. The DOM changes only at mutation; the user sees it only at paint.

↑ play a little first, then dig in