Render Phase vs Commit Phase
Definition
The React architecture splits work into two distinct phases. The Render Phase is pure, can be paused/aborted, and calculates what changes need to be made. The Commit Phase is synchronous, cannot be interrupted, and applies those changes to the real DOM.
Explain Like I'm New
Render Phase: The general draws up battle plans on a map. They might draw, erase, and redraw several times as new information comes in (Concurrent Mode). Commit Phase: The general gives the final order and the troops execute the plan in reality. Once the order is given, it cannot be stopped.
Real World Example
If you type into an input field very fast, React might calculate the UI changes for the letter "a" (Render phase), but before it updates the screen (Commit phase), you type "b". In React 18, React can throw away the "a" battle plan, calculate "ab", and only Commit once to the screen, saving performance.
Common Use Cases
- •Understanding why `useEffect` fires when it does
- •Understanding React 18 Concurrent rendering
- •Separating pure logic from side effects
Terminal Output
Interview Questions
basic
- What happens during the Render Phase?
- What happens during the Commit Phase?
intermediate
- In which phase does `useEffect` run?
- In which phase does `useLayoutEffect` run?
advanced
- Why is it dangerous to mutate variables during the Render Phase?
- How does React Fiber enable the Render Phase to be interruptible?
trick
- If a component returns `null`, does the Commit Phase still happen?