updated
React Commit Phase: Sub-phases, Layout and Passive Effects
The React commit phase runs before mutation, mutation and layout in one synchronous pass, then passive effects. Where each effect and its cleanup runs.

The short answer
The commit phase is the step after rendering where React applies the result to the DOM. It runs three sub-phases in one synchronous pass, then passive effects:
- Before mutation. React reads the old DOM. Class components get
getSnapshotBeforeUpdate. - Mutation. React inserts, updates and removes DOM nodes and detaches old refs.
useInsertionEffectcleanups and setups run here, and so douseLayoutEffectcleanups of updated and removed components. - Layout. Refs are attached, then
useLayoutEffectsetups run, along withcomponentDidMountandcomponentDidUpdate. The browser hasn't painted yet. - Passive effects. All
useEffectcleanups run, then alluseEffectsetups. Usually after paint.
Nothing interrupts those three sub-phases, not even a higher-priority update. Only the render phase can be paused or thrown away. React 19.3 adds one wrinkle: when a transition animates a <ViewTransition>, React hands mutation and layout to the browser's document.startViewTransition(), so they run a moment later, after the browser has captured the old screen.
"Usually after paint" has two exceptions. If the update came from a discrete event like a click or a key press, React may run your effects before the browser paints. In the source, every commit in the sync lane (discrete events and flushSync) flushes its passive effects at the end of the commit. And React always flushes leftover passive effects before it starts on the next update, so they never pile up across commits.
Knowing this matters when you need to know exactly when a ref is populated, why useLayoutEffect prevents a flicker but useEffect doesn't, why child effects run before parent effects, and what useInsertionEffect is actually for.
The commit phase starts where diffing ends
React's work splits into two main phases:
- Render phase - calls your component functions, builds a new fiber tree, diffs it against the current tree. Pure computation. Can be interrupted and replayed in concurrent mode. Produces a list of effects to apply.
- Commit phase - takes that list and applies it. Synchronous and uninterruptible. This is the only place that touches the real DOM.
The render phase can be discarded and re-run - React does this in Strict Mode (deliberately) and in concurrent mode (when a higher-priority update arrives). The commit phase never restarts once it begins.
Before Mutation: the last look at the old DOM
Before React touches the DOM, it runs commitBeforeMutationEffects. At this point the work-in-progress tree exists in memory but the current DOM has not changed yet.
The main thing that happens here is getSnapshotBeforeUpdate for class components - it lets you read layout information (scroll position, element dimensions) before any mutations occur. The return value gets passed to componentDidUpdate.
class ScrollableList extends React.Component {
getSnapshotBeforeUpdate(prevProps, prevState) {
// DOM hasn't changed yet - safe to read scroll position
if (prevProps.items.length < this.props.items.length) {
const list = this.listRef.current;
return list.scrollHeight - list.scrollTop;
}
return null;
}
componentDidUpdate(prevProps, prevState, snapshot) {
// snapshot = value returned from getSnapshotBeforeUpdate
if (snapshot !== null) {
const list = this.listRef.current;
list.scrollTop = list.scrollHeight - snapshot;
}
}
}For function components, nothing user-visible happens in this sub-phase. React also schedules passive effects (useEffect) here - it sets a flag that passive effects need to run, but does not execute them yet.
Mutation: the only moment the DOM changes
This is where the DOM actually changes. React walks the fiber tree and applies three kinds of operations:
- Placement - inserts new DOM nodes (
Node.appendChild,Node.insertBefore) - Update - changes props on existing nodes (sets attributes, event listeners, styles)
- Deletion - removes nodes and unmounts components
Deletion runs first within each subtree, so React always cleans up before inserting. This prevents briefly having both old and new versions of a node in the DOM.
Cleanup effects run here too. If a component is being deleted, its useLayoutEffect cleanup and useInsertionEffect cleanup fire during the mutation sub-phase. React runs the cleanups of the whole deleted subtree first and removes its DOM nodes after that, so componentWillUnmount and a layout cleanup can still read the element they're about to lose.
Also happening here: useInsertionEffect runs during the mutation sub-phase, before any layout effect. React's docs say it may run before or after the DOM has been updated, and refs aren't attached yet. Its purpose is narrow - injecting CSS-in-JS styles before any layout is measured. Libraries like styled-components and Emotion use this to ensure styles exist before useLayoutEffect reads layout:
// useInsertionEffect fires before any layout effect
// Only use this in CSS-in-JS libraries, not in application code
useInsertionEffect(() => {
const styleSheet = document.createElement('style');
styleSheet.textContent = `.my-class { color: red; }`;
document.head.appendChild(styleSheet);
return () => document.head.removeChild(styleSheet);
}, []);For application code, useInsertionEffect is almost never the right tool. Its timing is too early - you cannot reliably read DOM state from it.
At the end of the mutation sub-phase, React does something critical: it swaps the current tree. The work-in-progress tree becomes the new current tree (root.current = finishedWork). This happens between mutation and layout so that:
componentWillUnmountsees the old tree as current (needed for cleanup)componentDidMount/componentDidUpdatesee the new tree as current (needed for reading updated state)
Layout: refs are set and the browser hasn't painted yet
The DOM is now updated. The browser has not yet painted. React runs commitLayoutEffects.
This is where useLayoutEffect fires - synchronously, before the browser gets a chance to paint:
useLayoutEffect(() => {
// DOM is updated, browser hasn't painted yet
// Safe to read layout and make synchronous changes
const rect = ref.current.getBoundingClientRect();
setTooltipPosition({ top: rect.bottom, left: rect.left });
}, []);Because this runs synchronously and blocks painting, any state update you make inside useLayoutEffect forces an additional render before the browser shows anything. The user never sees the intermediate state - only the final result.
Class lifecycle methods componentDidMount and componentDidUpdate also fire here.
Refs are attached during the layout sub-phase. React walks the tree child first, so the refs on the elements a component rendered are set before that component's useLayoutEffect runs. This means ref.current is available inside useLayoutEffect but was null during rendering.
useEffect runs after paint, not right after the commit
useEffect is not part of the synchronous commit phase. After React finishes all three sub-phases and the browser has had a chance to paint, React runs passive effects asynchronously:
This is why useEffect cannot prevent layout flicker - the browser has already painted by the time it runs. But it is also why useEffect is the right choice for most side effects: it doesn't block the user from seeing the UI update.
The exception, covered in the short answer, is an update from a click or another discrete event: then React runs passive effects at the end of the commit, before paint. Even then, the browser may paint before the state updates from those effects are processed. If you need a guarantee, use useLayoutEffect.
One update, every callback in order
Putting it all together - here is the order in which everything runs for a component update:
Try it: press Update and read the log top to bottom. Renders go parent first, effects go child first, and in each phase all the cleanups run before any of the new effects.
import { useEffect, useLayoutEffect, useState } from 'react';
import './styles.css';
const lines = [];
// Written straight to the DOM: putting the log in React state would cause more renders to log.
function log(text) {
lines.push(text);
const el = document.getElementById('log');
if (el) el.textContent = lines.map((l, i) => `${String(i + 1).padStart(2)}. ${l}`).join('\n');
}
function useLifecycleLog(name, value) {
log(`render ${name}`);
useLayoutEffect(() => {
log(`layout effect ${name}`);
return () => log(`layout cleanup ${name}`);
}, [name, value]);
useEffect(() => {
log(`effect ${name}`);
return () => log(`effect cleanup ${name}`);
}, [name, value]);
}
function Child({ value }) {
useLifecycleLog('Child', value);
return <p className="child">Child sees {value}</p>;
}
function Parent({ value }) {
useLifecycleLog('Parent', value);
return (
<div className="parent">
<p>Parent has {value}</p>
<Child value={value} />
</div>
);
}
export default function App() {
const [value, setValue] = useState(0);
const update = () => {
lines.length = 0;
// From a timer, like most real updates: React flushes effects caused by a click
// before paint, while effects from other updates wait until after paint.
setTimeout(() => setValue((v) => v + 1));
};
return (
<main>
<button onClick={update}>Update</button>
<Parent value={value} />
<pre id="log" />
</main>
);
}Child Effects Run Before Parent Effects
This is one of the most misunderstood details. Effects run bottom-up - children before parents:
function Parent() {
useEffect(() => {
console.log('Parent effect');
}, []);
return <Child />;
}
function Child() {
useEffect(() => {
console.log('Child effect');
}, []);
return <div />;
}
// Output:
// Child effect
// Parent effectReact traverses the fiber tree depth-first. When processing effects, it walks to the deepest child first and works its way back up. This mirrors the DOM - children are fully mounted before parents are notified.
The same applies to useLayoutEffect. This matters when a parent's layout effect depends on measurements that a child's layout effect might have modified.
Cleanup Runs Before the Next Effect
When a dependency changes, React runs the previous effect's cleanup before running the new effect. The order is:
useEffect(() => {
console.log('effect', count);
return () => console.log('cleanup', count);
}, [count]);
// count changes from 0 to 1:
// cleanup 0
// effect 1This applies to both useEffect and useLayoutEffect. Cleanup always precedes the new effect run. The cleanup sees the values from the render in which it was created - the count in the closure is the old count, not the new one.
For useLayoutEffect, cleanup runs synchronously during the mutation sub-phase before the next layout callback fires. For useEffect, cleanup runs asynchronously as part of the passive effects pass, right before the new callback.
Five traps that come from getting the timing wrong
Trap 1: Reading layout in useEffect instead of useLayoutEffect
// Bug: tooltip flickers because browser paints before position is set
useEffect(() => {
const rect = anchorRef.current.getBoundingClientRect();
setPosition({ top: rect.bottom });
}, []);
// Fix: runs before paint
useLayoutEffect(() => {
const rect = anchorRef.current.getBoundingClientRect();
setPosition({ top: rect.bottom });
}, []);The rule: if the result of your effect would cause a visible flash if deferred, use useLayoutEffect. Otherwise use useEffect.
Trap 2: Expecting a ref to be populated during render
// Bug: ref.current is null during render
function Component() {
const ref = useRef(null);
// ref.current is null here - render phase, not commit phase
const width = ref.current?.offsetWidth; // undefined
return <div ref={ref} />;
}
// Fix: read ref inside a layout effect
function Component() {
const ref = useRef(null);
const [width, setWidth] = useState(0);
useLayoutEffect(() => {
// ref.current is populated here - layout sub-phase
setWidth(ref.current.offsetWidth);
}, []);
return <div ref={ref}>{width}px wide</div>;
}Trap 3: setState inside useLayoutEffect causes double render
useLayoutEffect fires synchronously before paint. If you call setState inside it, React runs another render and another commit before the browser paints. Users never see the intermediate state - but you get extra work:
// This causes two renders before paint:
// 1. Initial render with default position
// 2. Re-render after useLayoutEffect sets position
useLayoutEffect(() => {
setPosition(measureElement(ref.current));
}, []);For initial measurement this is often unavoidable. For updates, check whether you can calculate the value during render instead to avoid the extra pass.
Trap 4: Missing cleanup in useLayoutEffect
Because useLayoutEffect cleanup runs synchronously during the mutation sub-phase, a missing cleanup can leave stale listeners or DOM modifications that interfere with the next render:
// Bug: ResizeObserver leaks on every re-render
useLayoutEffect(() => {
const observer = new ResizeObserver(handleResize);
observer.observe(ref.current);
// Missing: return () => observer.disconnect();
}, []);
// Fix:
useLayoutEffect(() => {
const observer = new ResizeObserver(handleResize);
observer.observe(ref.current);
return () => observer.disconnect();
}, []);Trap 5: Assuming useEffect fires immediately after render
useEffect fires after the browser paints - which could be tens of milliseconds after the render completes. In concurrent mode, the gap can be even larger. Code that assumes useEffect runs synchronously with the render will fail:
// Bug: assumes the effect has already run by the time this check fires
const hasFetched = useRef(false);
useEffect(() => {
hasFetched.current = true;
fetchData();
}, []);
// Immediately after render, hasFetched.current is still false
console.log(hasFetched.current); // false - effect hasn't run yetIf you need to know whether an effect has run, track it with state rather than a ref read outside the effect.
Which effect hook to reach for
useInsertionEffect - CSS-in-JS libraries only. Inject styles before layout
is measured. Do not use in application code.
useLayoutEffect - Synchronous DOM measurement or mutation that would
cause a visible flicker if deferred. Tooltip positioning,
scroll restoration, DOM dimension reads that affect layout.
useEffect - Everything else. Data fetching, subscriptions, logging,
analytics, timers. The right default for 95% of effects.Start with useEffect. Only switch to useLayoutEffect when you see a visible flicker or need to read a DOM measurement that affects what the user first sees.
The timing rules on one card
The commit phase is where React's declarative model meets the imperative DOM:
- Before Mutation - reads the DOM before any changes, fires
getSnapshotBeforeUpdate - Mutation - applies DOM insertions, updates, and deletions; fires
useInsertionEffectanduseLayoutEffectcleanups - Layout - populates refs, fires
useLayoutEffectcallbacks andcomponentDidMount/componentDidUpdate - Passive Effects - fires
useEffect, usually after the browser has painted, but before paint for clicks and other discrete events
The key ordering rules: children before parents, cleanups before new effects, layout before paint, passive usually after paint.
Get the timing right, and you avoid flickers, stale refs, and effects that fire on values they should never have seen.
Have a question, spotted a mistake or see it differently? I'd genuinely like to hear it.
Interview questions on this
All questionsRelated posts
All posts- , 11 min readReact Compiler 1.0: Automatic Memoization and useMemoReact Compiler is stable since 1.0 (October 2025), but React 19 does not memoize on its own. What the compiler does, when useMemo stays, and "use memo".
- , 7 min readReact Rendering ExplainedHow React rendering works under the hood: reconciliation, virtual DOM, batching, and what actually triggers a re-render.
- , 12 min readReact State Management: Zustand vs Jotai vs TanStack QueryWhich React state tool for which state: TanStack Query for server data, Zustand or Jotai for shared client state, useState for local and the URL for filters.


