React Fiber

An interactive tutorial on how React Fiber works, read from React 19's own source: the work loop, the fiber tree, keys, commit and concurrent rendering.

A frontend app built by Ananda Rizki. More of them at Labs.

Labs — by Ananda Rizki

React Fiber

Tutorial

Eleven lessons, each a small component tree with React's work loop walked across it one fiber per frame: beginWork down, completeWork back up, with the code panel showing React's own source and saying, on every lesson, whether what you are reading is verbatim or simplified. It starts before the jargon does — what setState really does (it writes a lane and walks to the root, it does not render), and why the pre-Fiber recursive render could not be paused, because the position in a recursive walk is the JavaScript call stack and a call stack cannot be saved in a variable. From there: the fiber tree as a linked structure, hooks as a second linked list and why that is the real reason for the rules of hooks, the work loop, how keys decide which fiber is which, bailouts, the two trees and the pointer swap, where useLayoutEffect and useEffect actually run, and what happens to half-finished work when something urgent arrives. Every lesson also says why React is built that way and what the choice costs. The fibers are laid out the way the pointers point: child drops down, sibling goes right, return comes back up the left gutter, so reading the diagram is reading the data structure. A twelfth view is a captured profile rather than a drawing — the same 120-component update rendered plainly and inside startTransition, measured at 83.1 ms in one block against 5.5 ms in sixteen, for the same total work — and a Sources view lists every claim with the React file, the function and the constant it came from. Written for someone who has never opened React's source, and built so they do not have to take any of it on trust.

Built with
  • react
  • tailwind
  • motion
Related

Built by Ananda Rizki, a software engineer and designer, one of the small web apps he writes for fun.

Explore more apps on Labs