Fiber & Reconciliation
How React walks a tree, what a Fiber is, render vs commit, and why scheduling made concurrent rendering possible. · 4 lessons · click a card to expand
Part of the React 16 → 19.3 evolution reference. Expand a card, then use chapter links in the sidebar.
This chapter is conceptual. APIs that *use* Fiber (createRoot, startTransition, Suspense) are in later chapters. Pair with React 16 for Error Boundaries and Concurrent Rendering for scheduling.
Reconciliation
1 item01Reconciliation is how React diffs treesReact 16
setState / a hook updater. React renders a new description ({ type, props, key }) and diffs it against the last description.What is it?
Reconciliation is not “Virtual DOM is faster than DOM.” It is “avoid touching the DOM unless the description changed.” The Virtual DOM is a description. The DOM is the output.
Why was it introduced?
Naive innerHTML = wholePage is simple and slow. React’s bet: developers describe UI as a function of state; the library computes the delta.
Before Fiber (stack reconciler)
The pre-16 reconciler walked the tree recursively and could not pause. A deep update locked the main thread until the whole tree finished. That is why large lists felt janky even when “only one row changed” if the parent re-rendered a huge subtree.
With Fiber
The same public API (render a tree) is implemented as a linked list of Fiber nodes that can be interrupted. Reconciliation became a unit of work, not a single stack call.
setState
→ render phase (may restart, may be interrupted in concurrent mode)
→ commit phase (DOM mutations, refs, layout effects — synchronous)Real-world examples
1. Product filter on an e-commerce grid
Problem: ticking “In stock” re-renders 800 cards. Reconciliation still walks those 800 fibers, but only cards whose props changed should hit the DOM.
function ProductGrid({ products, inStockOnly }) {
const visible = inStockOnly ? products.filter((p) => p.inStock) : products;
return (
<ul>
{visible.map((p) => (
<ProductCard key={p.id} product={p} />
))}
</ul>
);
}Why it matters: `key={p.id}` tells reconciliation “this is the same product,” so it updates in place instead of unmounting. Wrong keys (index, after sort) cause input state to jump between rows.
2. Admin dashboard tab switch
Problem: switching from “Orders” to “Users” should unmount Orders and mount Users, not try to morph a table into a user list.
{tab === "orders" ? <OrdersTable key="orders" /> : <UsersTable key="users" />}Different type (and/or key) → React throws away the old subtree. That is reconciliation, not CSS hiding.
3. Chat thread append
Problem: a new message should add one bubble, not rebuild the transcript.
function Thread({ messages }) {
return messages.map((m) => <Bubble key={m.id} body={m.body} />);
}Stable keys at the end of a list are O(1) inserts at the tail. Reversing without keys makes React reuse DOM nodes in the wrong order.
When should I use this knowledge?
Whenever something “randomly remounts,” focus is lost, or CSS transitions replay — you are debugging reconciliation, not CSS.
When should I NOT use it?
Do not hand-optimize “to help the Virtual DOM.” Prefer correct keys, pulling state down, and memo only when profiling says so.
Common mistakes
- Index keys on a sortable list
- Using a new
keyon every render (key={Math.random()}) — forced remount - Expecting reconciliation to skip children of a parent that re-rendered (it will visit them unless you memo)
Performance considerations
Reconciliation is CPU work on the main thread. Concurrent rendering (React 18) can time-slice the render phase. The commit phase is still synchronous.
Related APIs
Fiber, React.memo, key, createRoot
Interview notes
- Reconciliation compares element
typeandkey. - Same type + same key → update props. Different type → tear down and mount.
- Keys are for siblings, not globally unique IDs across the app.
<input> inside a list item, sort the list with key={index}, and type in the first row. Watch the text jump.Fiber
1 item02A Fiber is a unit of workReact 16
child, sibling, return (parent). That list is what makes pausing and resuming possible.new Fiber(). You will debug it in DevTools as the component tree.What is it?
Each Fiber stores:
- What to render (
type,pendingProps) - The last rendered output (
memoizedProps,memoizedState) - Links to the rest of the tree
- Flags for what the commit phase should do (Placement, Update, Deletion, …)
- For hooks: a linked list of hook states on function-component fibers
Why was it introduced?
The stack reconciler used the JavaScript call stack. You cannot yield mid-stack without losing the walk. Fiber reified that stack into objects in the heap so React can:
- Pause work to handle a click
- Reuse finished work
- Hydrate incrementally
- Show a Suspense fallback without aborting the whole page
- Recover from render errors (Error Boundaries)
Before React 16
render(App)
render(Layout)
render(Sidebar) // cannot pause here
render(Main)
render(Table) // 20ms of work — click waitsA long render meant dropped frames and delayed input.
With Fiber
workInProgress fiber: Table
→ complete unit
→ shouldYield()? if yes, pause
→ later: resume at the next fiberIn legacy ReactDOM.render (16–17), this architecture existed but most updates still ran as if they were synchronous. Concurrent features are opt-in in 18 via `createRoot`.
How it works (practical)
React keeps two trees conceptually:
- current — what is on screen
- workInProgress — the tree being built
On commit, workInProgress becomes current. This is double buffering.
current: App → Layout → Main
workInProgress: App → Layout → Main' (new props)
commit: swap pointers, run DOM opsReal-world examples
1. Search-as-you-type on a 10k-row table
Problem: each keystroke must update the input (urgent) while filtering can wait (non-urgent). Fiber is why useTransition can deprioritize the filter render.
2. Route change in a SaaS app
Problem: navigating to /settings should not freeze a running chart animation on the previous page forever — concurrent rendering can abandon an in-progress tree if a newer update supersedes it.
3. Infinite scroll in a social feed
Problem: appending 20 posts should not block tapping “Like” on a visible card. The like is a small urgent update; the append is more work. Scheduling (built on Fiber) distinguishes them.
When should I use this knowledge?
When explaining jank, Error Boundaries, Suspense, or “why did this effect run twice in Strict Mode.” Fiber is the shared substrate.
When should I NOT use it?
Do not poke internal fiber fields in app code. They change between versions. Use DevTools and public APIs.
Common mistakes
- Saying “Fiber is the Virtual DOM” (Fiber is the reconciler’s data structure)
- Assuming React 16 apps are concurrent (they are not, unless you later use
createRoot+ concurrent APIs)
Performance considerations
Fiber overhead is real (more objects than a recursive stack). The payoff is schedulable work and features that were impossible on the stack reconciler.
Related APIs
Error Boundaries (16), lazy/Suspense (16.6), concurrent rendering (18)
Interview notes
- Fiber = incremental reconciler shipped in React 16.
- Two phases: render (pure, interruptible in concurrent mode) and commit (DOM, not interruptible).
- Hooks live on the function component’s fiber (
memoizedStatechain).
child / sibling / return once. That drawing is worth more than memorizing lane numbers.Render vs commit
1 item03Rendering computes; committing mutatesReact 16
Render phase
- Call function components /
render()methods - Compare elements
- May run twice in development under Strict Mode (React 18+)
- Must be pure: same props/state → same output, no DOM writes, no subscriptions
function Price({ cents }) {
const dollars = (cents / 100).toFixed(2); // OK: derived during render
return <span>${dollars}</span>;
}Commit phase
- Before mutation:
getSnapshotBeforeUpdate - Mutation: DOM inserts/updates/deletes
- Layout:
useLayoutEffect,componentDidMount/DidUpdate, ref callbacks - Passive:
useEffect(after paint)
Before you knew the split
People put document.getElementById or window.addEventListener directly in the component body. That ran during render — including during interrupted or double renders.
With the split
function ChatScroll({ messages }) {
const endRef = useRef(null);
useLayoutEffect(() => {
endRef.current?.scrollIntoView();
}, [messages]);
return (
<div>
{messages.map((m) => (
<p key={m.id}>{m.text}</p>
))}
<div ref={endRef} />
</div>
);
}Measurement and scroll belong in layout (before the browser paints) so the user does not see a flash at the wrong scroll position. Network fetching belongs in `useEffect` (after paint) or in a router/RSC loader.
Real-world examples
1. Checkout: focus the OTP field
Problem: after the SMS step mounts, focus the first input. useLayoutEffect + ref, not render-body focus().
2. Analytics dashboard: chart library
Problem: new Chart(canvas) needs a real DOM node. Create it in useEffect, destroy on cleanup. Render only returns <canvas ref={ref} />.
3. Notification toasts: measure height for stack
Problem: stacking toasts needs getBoundingClientRect. That is commit-time layout work, not render-time.
When should I use render vs commit knowledge?
Any time you touch the DOM, a third-party widget, or “I need the width of this node.”
When should I NOT use it?
Do not use useLayoutEffect for data fetching — it blocks paint. Do not use useEffect for “hide flicker of wrong layout” if the flicker is a layout issue.
Common mistakes
- Updating state in render without a condition (infinite loop)
- Reading
ref.currentduring render to decide JSX (ref is not set yet) - Assuming
useEffectran before the user saw the screen (it did not)
Performance considerations
Long useLayoutEffect delays paint (like a sync layout). Long useEffect does not block first paint but can delay interactivity.
Related APIs
useEffect, useLayoutEffect, useInsertionEffect (18, for CSS-in-JS libraries)
Interview notes
- Render = calculate next tree. Commit = apply it.
- Effects are commit-phase (passive after paint).
- Strict Mode double-invoking render/effects is a dev-only check that your render is pure and your effects clean up.
console.log in the component body vs in useEffect. Navigate away and back. Note cleanup.Scheduling
1 item04Scheduling decides which update wins the CPUReact 18
setState is equal. Typing in a search box is urgent. Filtering 50k rows is important but delayable.urgent (click, input, discrete events)
|
+-- React wants this on screen immediately
|
transition / deferred
|
+-- React may show the old UI, then replace when the new tree is readyWhy it was needed
Users blame “React is slow” when the input lags, even if the filter is correctly expensive. The old model: one update queue, all synchronous.
Before React 18
function Search({ items }) {
const [query, setQuery] = useState("");
const results = items.filter((item) => item.name.includes(query));
return (
<>
<input value={query} onChange={(e) => setQuery(e.target.value)} />
<ResultList rows={results} />
</>
);
}Each keystroke filters immediately. The input waits for the list.
With transitions (React 18)
const [query, setQuery] = useState("");
const [isPending, startTransition] = useTransition();
<input
value={query}
onChange={(e) => {
const next = e.target.value;
setQuery(next); // urgent: keep the input live
startTransition(() => setDeferredQuery(next)); // list can wait
}}
/>(See the full pattern on React 18 APIs.)
How it works
React 18+ uses lanes (bitmasks) on updates. The scheduler picks the highest-priority unfinished work. Concurrent render can throw away a half-built tree if a higher-priority update arrives.
You do not assign lanes yourself. You mark updates with startTransition or useDeferredValue.
Real-world examples
1. Product search (e-commerce) — keep the query input instant; defer the grid.
2. Sidebar nav in an admin app — highlight the clicked item immediately; load the heavy report inside a transition.
3. Chat: send button vs message list virtualization — the composer should never hitch because the list is measuring rows.
When should I use scheduling APIs?
When a state update is not a direct reflection of a user-controlled input (filters, tabs that mount heavy trees, typeahead result lists).
When should I NOT?
Do not wrap the controlled input’s own setQuery in a transition — the keystrokes will feel delayed. Do not use transitions for really cheap updates.
Common mistakes
- Putting both input and list on the same transitioned state
- Expecting transitions to make a slow API faster (they schedule rendering, not the network)
Performance considerations
Scheduling improves responsiveness, not necessarily throughput. Total CPU can be similar; the click still lands on time.
Related APIs
startTransition, useTransition, useDeferredValue, useSyncExternalStore (tears if the store updates at the wrong time)
Interview notes
- Fiber enabled scheduling; React 18 exposed it.
- Urgent vs transition is the user-facing model.
- Lanes are an implementation detail.
createRoot and concurrent features.useDeferredValue using the Performance panel — then read 19.2 Performance Tracks.