How it works
The render phase is a loop over fibers. Simplified from ReactFiberWorkLoop.js in React 19.3.1:
function workLoopConcurrentByScheduler() {
while (workInProgress !== null && !shouldYield()) {
performUnitOfWork(workInProgress);
}
}
function performUnitOfWork(fiber) {
// Render this fiber against its current copy; returns its first child, or null.
const next = beginWork(fiber.alternate, fiber, renderLanes);
fiber.memoizedProps = fiber.pendingProps;
if (next === null) completeUnitOfWork(fiber); // go to the sibling, or back up
else workInProgress = next;
}
workLoopSync is the same loop without shouldYield(). Whether React picks it depends on the update's lanes; that's the concurrent rendering question.
beginWork calls the component (or updates the class instance), reconciles the returned elements against the current children, and returns the first child fiber. If neither the fiber nor any descendant has work in this render's lanes (its lanes and childLanes are checked with a bitwise test), it skips the whole subtree.
completeUnitOfWork runs when a fiber has no children left: it creates or prepares the DOM node off screen, merges its children's flags into subtreeFlags, then moves to sibling, or to return when there is none.
Because the state of the walk is one variable, workInProgress, yielding is just leaving the loop; resuming is entering it again.
Double buffering. createWorkInProgress (in ReactFiber.js) takes a current fiber and returns its alternate, creating it only the first time. Its comment explains the choice: React needs at most two versions of the tree, so it pools the unused one. During the commit, root.current = finishedWork swaps the trees after the mutation phase and before the layout phase, so componentWillUnmount still sees the old tree and componentDidMount the new one. An interrupted render simply resets the work-in-progress copies next time; nothing on screen pointed at them.
Edge cases
- Text-only children.
<li>{label}</li> has no child fiber for the string: in the test, fiber.child was null. React sets a lone string as the element's text directly.
- The hook list lives on the fiber. For a function component,
memoizedState is the first hook, and each hook links to the next. A component calling useState(7) then useRef('r') had memoizedState.memoizedState === 7 and memoizedState.next.memoizedState.current === 'r'. That list is matched by call order, which is why hooks can't be called conditionally.
- Production keeps the structure. The production fiber had 22 fields; development adds profiler timings and
_debug* fields. The __reactFiber$ key was present in both.
Real-world scenario
A data table re-rendering 5,000 rows on every filter keystroke: under the stack reconciler, the input couldn't show the typed character until the whole table had rendered, and the only fixes were rendering less or debouncing. With Fiber the same render can be split: marked as a transition, the table renders in slices with the browser handling input between them, and a newer keystroke throws the half-built tree away. The reconciler change is invisible in the code; the new capability shows up only through the APIs that opt in.
Trade-offs
Fiber spends memory and indirection to buy control: two objects per element instead of a stack frame, about two dozen fields each, and a loop that is harder to follow than recursion. In return React gets pausing, prioritization, error recovery and kept-alive subtrees. The cost to application code is a contract, not a performance tax: because a render may now be paused, repeated or discarded, components must be pure, which Strict Mode checks by rendering twice in development.