- React
- React Internals: Fiber Architecture and Reconciliation
- Render Phase vs Commit Phase Mechanics
Render Phase vs Commit Phase Mechanics
The Render Phase is asynchronous and pure: React invokes component functions and diffs Fiber trees without touching the DOM, and work can be paused or discarded. The Commit Phase is synchronous and fast: React mutates the real DOM, executes layout effects, and schedules passive effects.
Key Learning Objectives
Differentiate between the Render Phase (computation) and Commit Phase (mutation).
Explain why the Render Phase must be 100% free of side-effects in Concurrent React.
Trace the three sub-phases of Commit: Mutation, Layout, and Passive effects.
Understand why StrictMode executes the Render Phase twice in development.
The Interview Problem & Context
Explain the fundamental differences between the Render Phase and Commit Phase in React. What operations are permitted in each phase, and why is the Render Phase interruptible while the Commit Phase is not?
1// PHASE 1: RENDER PHASE (Interruptible, pure computations, NO DOM mutations!)2// - Invokes Component render functions3// - Evaluates useState / useReducer initializers & updaters4// - Runs diffing algorithm to create workInProgress Fiber tree5// - In Concurrent React: Can be paused, restarted, or thrown away!67// PHASE 2: COMMIT PHASE (Synchronous, uninterruptible DOM operations)8// 1. Before Mutation Phase: Reads snapshot (getSnapshotBeforeUpdate)9// 2. Mutation Phase: Mutates real DOM (inserts, updates, deletes DOM nodes)10// 3. Layout Phase: Runs useLayoutEffect callbacks synchronously before paint11// --- Browser Repaint & Composite Screen ---12// 4. Passive Effects Phase: Runs useEffect callbacks asynchronously after paint
Deep Architectural Explanation
The Two Phases of React Execution
Understanding React requires decoupling rendering from DOM updating:
State Change
│
▼
[Render Phase] ──> (Pure computations, diffing, can be paused/discarded)
│
▼
[Commit Phase] ──> (Synchronous DOM mutations, useLayoutEffect, paint, useEffect)
1. The Render Phase
- Goal: Figure out what needs to change in the DOM.
- Characteristics: Fast, asynchronous, and interruptible.
- What happens: React calls component functions, resolves hook updates, and marks Fibers with effect flags (Placement, Update, Deletion).
- Rule: Must be pure! React may start rendering, pause when a user types, discard the draft render, and restart. Any side-effects (like incrementing a counter or making a network request) would run multiple times!
2. The Commit Phase
- Goal: Apply calculated changes to the browser DOM.
- Characteristics: Synchronous and uninterruptible.
- Why it must be synchronous: If the browser painted while React was halfway through inserting a list of 10 items, the user would see broken, flickering partial UI.
- Sub-phases:
- Mutation: React updates real DOM nodes.
- Layout: Runs
useLayoutEffectsynchronously. - Paint: The browser renders pixels to the screen.
- Passive: Runs
useEffectcallbacks asynchronously.
Common Interview Traps & Pitfalls
Assuming "rendering" means "painting pixels to the browser screen" (rendering is just calculating the virtual element diff).
Triggering network requests or modifying localStorage during the Render Phase.
Believing useEffect runs during the Commit Mutation sub-phase (it runs asynchronously after browser paint).
Senior Interviewer Follow-Up Probes
Why does React 18 Concurrent Mode discard an entire Render Phase if an urgent update arrives?
How does getSnapshotBeforeUpdate capture scroll position right before the DOM is mutated?
What happens if a state update is scheduled inside useLayoutEffect vs useEffect?
Frequently Asked Interview Questions
Why can the Render phase be discarded in Concurrent React?
If a higher-priority update (like a user keystroke) occurs while React is rendering a low-priority background transition, React throws away the draft render to respond to the user immediately.
Can you trigger state updates during the Commit phase?
Yes, updating state inside useLayoutEffect or useEffect schedules a new render pass, but doing so in useLayoutEffect forces a synchronous re-render before paint.
Which phase does React StrictMode run twice?
StrictMode intentionally runs the Render phase twice in development to verify that component functions are pure and idempotent.
When do DOM nodes get created vs attached to the document?
Host DOM nodes are instantiated during the Render phase, but they are only appended to the actual document tree during the Commit Mutation phase.
