Render Phase
February 9, 20261 min readpart 03/13
The render phase is where React figures out what changed. It's pure computation — no DOM mutations. This phase is interruptible in concurrent mode.
The Work Loop
function workLoopConcurrent() {
while (workInProgress !== null && !shouldYield()) {
performUnitOfWork(workInProgress);
}
}
function performUnitOfWork(unitOfWork) {
const next = beginWork(unitOfWork); // Process, return first child
if (next === null) {
completeUnitOfWork(unitOfWork); // No children → sibling or parent
} else {
workInProgress = next;
}
}shouldYield() checks if the browser needs the main thread back (via MessageChannel). If so, React pauses and resumes later exactly where it left off.
beginWork
Called for each Fiber going down the tree. Behavior depends on the Fiber's tag: FunctionComponent → calls the function (runs hooks); ClassComponent → calls render(); HostComponent → diffs props; ContextProvider → pushes new value onto internal stack.
completeWork
Called going back up. Creates actual DOM nodes (but doesn't insert them), bubbles effect flags from children into subtreeFlags, and builds the effect list of Fibers needing DOM mutations.
The Diffing Algorithm
Instead of O(n³) general tree diff, React uses two heuristics for O(n):
Heuristic 1: Different types produce different trees — a <div> changing to <span> tears down the entire subtree.
Heuristic 2: Keys identify stable elements. For list children, React builds a Map keyed by key (or index), then walks the new list matching against it.
Why index keys are bad: inserting at the beginning shifts every index, so React thinks every element changed — causing unnecessary unmounts and lost state.
Further reading
- How beginWork() Processes Each Fiber Type (deep dive) jser.dev annotated source walkthrough of the beginWork switch
- Reconciliation — React Docs (docs) Official explanation of the two heuristics and O(n) diffing
- React as a UI Runtime (article) Dan Abramov covers host trees, reconciliation, and the rendering model
- Reconciliation and Keys in Depth (article) Nadia Makarevich on key behavior, index pitfalls, and reset patterns
- How React Diffs Lists Internally (deep dive) Step-by-step trace of ReactChildFiber.js key matching algorithm