Nagaraja Markapuram

React Fiber Deep Dive: The Engine Behind Modern React

Understanding how React Fiber transformed rendering into a cooperative scheduling system.

Why React Needed Fiber

Early versions of React used a stack-based reconciliation model:

  • Rendering was synchronous
  • Once started, it could not be interrupted
  • Large updates blocked the main thread

šŸ‘‰ Result: dropped frames and unresponsive UI.


What is React Fiber?

React Fiber is a reimplementation of the call stack in JavaScript, transforming React into a cooperative scheduler.

Instead of processing the entire tree at once, React now:

  • Breaks work into smaller units
  • Schedules them based on priority
  • Can pause, resume, or discard work

Core Idea: Work Units

Each component becomes a unit of work, allowing React to:

  • Split rendering into chunks
  • Yield control back to the browser
  • Keep UI responsive

Key Capabilities Introduced

šŸ”¹ Incremental Rendering

  • Breaks rendering into smaller tasks
  • Avoids long blocking operations

šŸ”¹ Time Slicing

  • React yields control every few milliseconds
  • Keeps input, animations, and scrolling smooth

šŸ”¹ Concurrency

  • Multiple UI states can be prepared simultaneously
  • High-priority updates interrupt low-priority work

Fiber Architecture (Visual)

šŸ‘‰ Each node above is a Fiber Node (unit of work)


Fiber Node Structure

Each component is represented by a Fiber Node containing:

  • child → first child
  • sibling → next sibling
  • return → parent

šŸ‘‰ This forms a linked structure, not a simple tree.


šŸ” Dual Tree (Double Buffering)

React maintains two trees:

  • Current Tree → UI currently on screen
  • Work-in-Progress Tree → UI being prepared

Flow

šŸ‘‰ This ensures smooth updates without breaking UI


🚦 Lane-Based Priority System

React assigns updates to lanes (bitmasks):

  • Discrete → clicks, typing (highest priority)
  • Continuous → scroll, drag
  • Default → data updates

šŸ‘‰ High-priority updates can interrupt lower ones


Rendering Phases

1. Render Phase (Interruptible)

  • Builds the new tree
  • Can be paused, resumed, or aborted

2. Commit Phase (Synchronous)

  • Applies changes to the DOM
  • Cannot be interrupted

End-to-End Flow

User Action ↓ Schedule Update (Lane Priority) ↓ Render Phase (Fiber Work Loop) ↓ Pause / Resume if needed ↓ Commit Phase ↓ DOM Updated


Why Fiber Matters

Fiber enables React to:

  • Avoid blocking the main thread
  • Prioritize important updates
  • Deliver smoother user experiences
  • Support modern features like streaming and concurrency

Key Takeaway

React is no longer just a rendering library — it is a scheduler for UI work.