Answer:
React Fiber is the complete rewriting of React's core reconciliation algorithm, released in React 16.
Why it was created:
Before Fiber (the "Stack Reconciler"), React navigated the virtual DOM tree recursively. Once a render cycle started, it executed synchronously on the browser's main thread and could not be paused, aborted, or split. If the component tree was very large, a render cycle could take more than 16ms (the budget for 60fps), causing dropped frames, laggy input fields, and stuttering animations (commonly called "jank").
The Fiber Concept:
A "Fiber" is a plain JavaScript object that represents a unit of work. It maps to a React element and a DOM node, but unlike elements, fibers are long-lived and mutable. They contain metadata about state, props, output, and references to other fibers (child, sibling, and return).
Cooperative Scheduling & Work Splitting:
Fiber transforms the execution model from a call stack to a linked list traversal. This allows React to divide the rendering work into small chunks and yield execution back to the browser's main thread when necessary (cooperative scheduling), utilizing browser APIs like requestIdleCallback or React's custom scheduler.
The Two-Phase Lifecycle:
- Render Phase (Asynchronous, Interruptible):
- React traverses the fiber tree (linked list) to compute changes (diffing).
- It builds a "work-in-progress" tree.
- This phase is non-blocking and can be paused, discarded, or restarted if higher-priority work (like user keyboard inputs) enters the scheduler.
- No physical side effects (DOM mutations) occur in this phase.
- Commit Phase (Synchronous, Uninterruptible):
- React takes the completed work-in-progress tree (the "effects list") and applies changes to the actual DOM.
- This phase must execute synchronously in a single pass to prevent user-facing UI inconsistencies (flickering).
- Lifecycle methods like
componentDidMount, componentDidUpdate, and effects like useLayoutEffect and useEffect are scheduled or fired here.