React Fiber is the core of modern React β but it often feels mysterious.
- Why does React re-render only part of the UI?
- How are Fiber nodes built?
- Are HTML tags Fiber nodes?
- What actually happens in the Render and Commit phases?
Letβs break everything down with simple explanations and intuitive examples.
π― What is React Fiber?
React Fiber is the internal rendering engine introduced in React 16.
It replaced the old synchronous renderer with a smarter system that supports:
- Incremental rendering
- Interruptible work
- Scheduling & task prioritization
- Concurrent rendering (React 18)
- Recoverable rendering (can pause/resume/discard)
Fiber is essentially Reactβs virtual CPU that processes rendering in small chunks rather than one big blocking task.
π§ Why Fiber Exists (The Problem)
Before Fiber, React used a call stackβbased renderer:
β Cannot pause work
β Cannot prioritize urgent updates
β Cannot split rendering into units
β Long render blocks everything (typing, scrolling, clicking)
Fiber solves all these by representing each component as a small βwork unitβ that React can schedule flexibly.
π§± Every Component Becomes a Fiber Node
Every JSX element you write generates a Fiber node.
β Component β Fiber
β DOM element β Host Fiber
β Text β Text Fiber
Example:
function App() {
return (
<div>
<h1>Hello</h1>
<button>Click</button>
</div>
);
}
Fiber tree:
App (FunctionComponent)
βββ div (HostComponent)
βββ h1 (HostComponent)
βββ #text "Hello" (HostText)
βββ button (HostComponent)
βββ #text "Click" (HostText)
Yes β every HTML tag is considered a Host Element.
π³ How the Fiber Tree Is Structured
Each Fiber node is connected using lightweight pointers:
-
childβ first child -
siblingβ next node on the same level -
returnβ parent
Example visual:
AppFiber
child β divFiber
divFiber
child β h1Fiber
sibling β null
h1Fiber
sibling β textFiber
textFiber
sibling β buttonFiber
buttonFiber
child β textFiber(child)
This avoids deep recursion and gives React full control over scheduling.
π² Current Fiber Tree vs Work-In-Progress Tree
React maintains two trees:
π© 1. Current Tree (whatβs on screen)
π¦ 2. Work-In-Progress Tree (being prepared)
When React finishes preparing the WIP tree, it swaps it with the current tree in a single atomic commit.
This is how React ensures DOM updates appear consistent.
β‘ Does a State Update Re-render the Entire App?
β NO β it does not.
When you update state inside a component, React:
β Starts reconciliation from that componentβs Fiber node
β Rebuilds only its subtree
β Affects neither siblings nor parents (unless needed)
Example:
Root
βββ Header
βββ Sidebar
βββ Dashboard
β βββ Chart
β βββ Filters
β β βββ SearchInput <-- state updates here
β βββ Table
βββ Footer
Only the SearchInput subtree (maybe 5β10 nodes) re-renders.
The 900+ other nodes remain untouched.
This is why React scales.
πΌ Why React Walks Upward First
When a state update happens, React:
- Marks the componentβs Fiber as βdirtyβ
- Walks upward using
.returnpointers to find:
- the nearest update root (usually the component itself)
- the lane/priority context
- Then walks down and reconciles only the subtree
This upward walk does not re-render parents β it just gathers context.
π¬ The Two Phases of React Fiber
Reactβs lifecycle is divided into:
π¦ 1. Render Phase (Reconciliation)
This is the phase where React determines what to render.
β Can be paused
β Can be interrupted
β Can be restarted
β Does NOT touch the DOM
β Its basically asynchronous
This is where React:
- Re-runs components
- Rebuilds the work-in-progress Fiber tree
- Compares new elements with old fibers
- Decides which DOM nodes need updating
- Computes effect list (what needs to change)
π How React walks in Render Phase
React uses a depth-first traversal of the Fiber tree:
beginWork β child β sibling β parent β next siblingβ¦
If React detects a higher-priority update (like user typing):
π¨ It can stop immediately
π¦ Save work
π¦ Resume later
π¦ Or discard the WIP tree
Example during typing:
- User types "H"
- React starts reconciliation of a long list
- User types "He"
React cancels the low-priority reconciliation and starts fresh with latest input.
This is the power of Fiber.
π© 2. Commit Phase
This is where React applies changes to the real DOM.
β ALWAYS synchronous
β CANNOT be interrupted
β Must finish completely
β Runs very fast
Commit phase steps:
1οΈβ£ Before Mutation Phase
React runs:
getSnapshotBeforeUpdate- Pre-mutation layout preparations
Purpose: Measure DOM before any changes occur.
2οΈβ£ Mutation Phase
React:
- Inserts DOM nodes
- Removes nodes
- Updates props and attributes
- Applies className and styles
- Sets event listeners
This is the actual DOM manipulation step.
3οΈβ£ Layout Phase
React runs:
useLayoutEffect- Callback refs
Then the browser:
- Paints the updated UI
Finally React schedules:
-
useEffect(runs asynchronously after paint)
π Render Phase vs Commit Phase (Simple Analogy)
Render Phase = Planning
React decides what should change.
Commit Phase = Doing
React updates the DOM.
π₯ Putting It All Together
Letβs simulate a text input render:
User types a letter
β
React schedules update on SearchInputFiber
β
Render Phase:
- Re-run SearchInput
- Rebuild its subtree
- Compute what changed (maybe text node)
β
Commit Phase:
- Update input DOM value
β
Browser paints
Only that tiny subtree is touched β the rest of your app sleeps peacefully. π
π Summary
- Fiber allows React to pause, resume, and restart rendering.
- Every element (component, DOM tag, text) becomes a Fiber node.
- React keeps two Fiber trees: current + work-in-progress.
- State updates do not re-render the entire tree β only the affected subtree.
- Render Phase is interruptible; Commit Phase is not.
- Fiber is the backbone of concurrent rendering, transitions, and scheduling.
React Fiber is elegant, powerful, and optimized for responsiveness β exactly what modern UIs need.
Top comments (0)