π Understanding React Fiber: Incremental vs Concurrent Rendering
React Fiber introduced a new way to handle rendering in React, allowing work to be split into small chunks (slices), paused, resumed, and even discarded. But how does this affect what the browser actually sees? Letβs break it down.
π§© 1. Work-in-Progress (WIP) and Slices
- Each Fiber node is a unit of work.
- Rendering is divided into time slices.
- In each slice, React processes as many Fibers as it can before yielding back to the browser.
π Important: Slices are only about preparing work. They do not directly affect the DOM.
π 2. Pausing vs Discarding
- Pausing β If React runs out of time, it saves progress and continues in the next slice.
- Discarding β If a new higher-priority update comes in, React throws away unfinished WIP and restarts.
π¨ 3. When Does the Browser See Updates?
- During Render (slices) β React is only preparing the Fiber tree. β No DOM updates yet.
- At Commit Phase β React flushes the finished tree to the DOM in one atomic step. β Browser paints changes here.
π Even if rendering happens in 5 slices, the browser only updates after commit.
π 4. Why Is It Still Called Incremental Rendering?
- React doesnβt block the browser with a long, synchronous render.
- Rendering work is split across slices.
- Browser stays responsive in between.
π The incremental part is about time-slicing the render work, not about incremental DOM commits.
π 5. Example Walkthrough
Imagine typing into an input that triggers a huge list render.
Without Fiber (old stack reconciler)
- Input change β whole list renders synchronously.
- Browser frozen until work completes.
With Fiber (incremental rendering)
- Slice 1: Input Fiber processed.
- Yield β browser stays responsive.
- Slice 2β5: List Fibers processed gradually.
- Final slice β Commit happens, DOM updated.
β‘οΈ 6. Concurrent Rendering
Concurrent rendering builds on incremental rendering by allowing partial commits.
- Commit input immediately β user sees instant feedback.
- Render list in background.
- If user types again β discard old WIP and restart fresh.
β This makes UI feel even smoother.
Top comments (0)