A Appendix
Appendix A · React Source Code File Organization
The four bundles below draw a clean boundary between what React is and where it runs. Every function discussed in this course lives in one of these files; the diagram shows the full call-flow across them, and the table maps each architectural concern to its home.
A.1 · Call-flow across packages
┌─────────────────────────────────────────────────────────────────────────────┐
│ USER ACTIONS │
│ setState / useReducer startTransition flushSync User Events │
└──────────────┬─────────────────┬────────────────┬──────────────┬────────────┘
▼ ▼ ▼ ▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ LANE ASSIGNMENT │
│ requestUpdateLane requestTransitionLane requestDeferredLane │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ UPDATE CREATION & QUEUEING │
│ dispatchSetState dispatchReducerAction │
│ enqueueConcurrentHookUpdate markRootUpdated │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ SCHEDULING ENTRY │
│ scheduleUpdateOnFiber ──▶ ensureRootIsScheduled │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ LANE SELECTION │
│ getNextLanes ──▶ lanesToEventPriority ──▶ lanesToSchedulerPriority │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ SCHEDULER INTEGRATION │
│ scheduleCallback ▶ requestHostCallback ▶ schedulePerformWorkUntilDeadline │
│ performWorkUntilDeadline ▶ workLoop ──▶ shouldYield (time-slice check) │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ RENDER ENTRY │
│ performConcurrentWorkOnRoot / performSyncWorkOnRoot │
│ └──▶ prepareFreshStack │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ RENDER LOOP │
│ renderRootConcurrent ──▶ workLoopConcurrent (checks shouldYield) │
│ renderRootSync ──▶ workLoopSync │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ FIBER PROCESSING │
│ performUnitOfWork ──▶ beginWork ──▶ completeUnitOfWork ──▶ completeWork│
│ │ │ │
│ LANE FILTERING (bubbles flags) │
│ isSubsetOfLanes / includesLane / includesSomeLane │
│ mergeLanes / removeLanes │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ COMPONENT RENDERING │
│ updateFunctionComponent ──▶ renderWithHooks ──▶ reconcileChildren │
│ │ │
│ HOOK PROCESSING │
│ mountState / updateState mountEffect / updateEffect │
│ updateReducer / updateReducerImpl │
└──────────────┬──────────────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ COMMIT PHASE │
│ commitRoot │
│ ├─▶ commitBeforeMutationEffects │
│ ├─▶ commitMutationEffects │
│ ├─▶ commitLayoutEffects │
│ └─▶ commitPassiveEffects ──▶ flushPassiveEffects │
│ ├─▶ commitPassiveMountEffects ──▶ commitHookEffectListMount │
│ └─▶ commitPassiveUnmountEffects ──▶ commitHookEffectListUnmount│
└─────────────────────────────────────────────────────────────────────────────┘
│
└──▶ ensureRootIsScheduled (loop continues)
Key flow paths:
- Update flow: User action → lane assignment → update creation → scheduling → render
- Render flow: Scheduler → render entry → render loop → fiber processing → component rendering
- Hook flow: Component rendering → hook processing → lane filtering → state update
- Commit flow: Render complete → commit phases → effect processing
- Loop flow: Commit complete → scheduling → next render
A.2 · Package responsibilities
react.js — Core API Layer (platform-agnostic)
Provides stable public APIs that work across all platforms. Contains no platform-specific code — no DOM, no iOS, no Android.
- Component APIs:
React.Component,React.PureComponent - JSX transformation:
React.createElement,React.cloneElement - Context API:
React.createContext - Hook interfaces (dispatcher pattern):
useState,useEffect,useReducer, … - Refs:
React.createRef,React.forwardRef - Fragments:
React.Fragment - Scheduler: task prioritization (decides when to work)
- Dispatcher registry:
ReactCurrentDispatcher(pointer to implementation)
What it actually does
// Public API — just delegates to the renderer
function useState(initialState) {
var dispatcher = resolveDispatcher();
return dispatcher.useState(initialState); // calls into react-dom
}
// JSX → React elements
React.createElement('div', { className: 'app' }, 'Hello');
react-dom.js — DOM Renderer (browser-specific)
Implements React for web browsers. Manipulates the real DOM. Contains the actual logic behind every hook.
- Hook implementations:
mountState,updateState,mountEffect,updateEffect - Reconciliation:
reconcileChildren,reconcileChildFibers(diffing algorithm) - Render phase:
beginWork,completeWork(build fiber tree) - Commit phase:
commitWork,commitMutationEffects(apply DOM changes) - DOM operations:
createElement,appendChild,removeChild - Event system: synthetic events, event delegation
- Hydration: SSR client-side takeover
- Entry points:
createRoot,hydrateRoot,render(legacy)
What it actually does
// Actual hook implementation
function mountState(initialState) {
var hook = mountWorkInProgressHook();
hook.memoizedState = hook.baseState = initialState;
// ... fiber node logic
return [hook.memoizedState, dispatch];
}
// Reconciliation (diffing)
function reconcileChildren(current, workInProgress, nextChildren) {
// Compare old vs new, create fiber nodes
}
// Commit changes to real DOM
function commitWork(finishedWork) {
const domElement = document.createElement('div');
parent.appendChild(domElement);
}
Complete end-to-end flow
// 1. Your code (uses react.js public API)
import React, { useState } from 'react';
import { createRoot } from 'react-dom/client';
function App() {
const [count, setCount] = useState(0); // ← react.js wrapper
return <div>{count}</div>; // ← react.js createElement
}
// 2. Entry point (react-dom.js)
const root = createRoot(document.getElementById('root'));
root.render(<App />);
// 3. Render starts — react-dom.js sets the dispatcher
ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
// 4. Hook execution
// useState(0)
// → react.js: dispatcher.useState(0)
// → react-dom.js: mountState(0) ← actual implementation
// 5. Reconciliation (react-dom.js)
// reconcileChildren() → build fiber tree, find diffs
// 6. Commit (react-dom.js)
// commitWork() → update real DOM
A.3 · react.js vs react-dom.js at a glance
| Concern | react.js | react-dom.js |
|---|---|---|
| Role | API interface / contract | DOM renderer / implementation |
| Platform | Universal | Web only |
| Hooks | Public API (proxy via dispatcher) | Actual implementation (logic) |
| Reconciliation | — | Diffing algorithm |
| Scheduler | Priority system (owns it) | Uses it |
| Fiber | — | Creates and manages fibers |
| DOM | — | createElement, appendChild |
| Events | — | Synthetic events |
| Entry points | — | createRoot, hydrateRoot |
| JSX | createElement | — |
| Context | createContext | — |
A.4 · One API, multiple renderers
The reason react.js and react-dom.js are separate is that the same
public API can be backed by completely different renderers:
// Same react.js import for all platforms:
import React, { useState } from 'react';
// Different renderers:
import { createRoot } from 'react-dom/client'; // Web
import { AppRegistry } from 'react-native'; // Mobile
import { render } from 'react-three-fiber'; // 3D
import { render } from 'ink'; // Terminal CLI
All use the same useState API from react.js, but each renderer
supplies its own implementation. react.js = "what to do" (API + Scheduler);
react-dom.js = "how to do it for the web" (implementation + DOM).
Appendix B · Additional Code References
Key external resources referenced in this course and useful starting points for exploring the live source.
| Resource | Description |
|---|---|
bholmesdev/simple-rsc |
A minimal, from-scratch React Server Components implementation (esbuild two-pass build + Flight streaming over a Hono server). Source for the worked examples covering build-time client references and the no-SSR request lifecycle in the RSC chapter. |
Appendix C · Glossary
Quick reference for React internals terminology used throughout the course.
Core concepts
| Term | Definition |
|---|---|
| Fiber |
Internal representation of a component instance. A JavaScript object
containing component type, props, state, and tree pointers
(child, sibling, return).
Introduced in React 16.
|
| Fiber tree |
Tree structure of Fiber nodes representing the component hierarchy.
React maintains two trees simultaneously: current
(on screen) and workInProgress (being built).
Introduced in React 16.
|
| Lane | A priority bit flag (power of 2) used to schedule and filter work. Multiple lanes can coexist in a single 32-bit integer, making priority tests and merges cheap bitwise operations. Introduced in React 18. |
| Scheduler | React's time-slicing system that yields to the browser every ~5 ms to keep the UI responsive. Handles when to work; the Lane system handles what and why. Introduced in React 16. |
| Reconciler | The algorithm that compares old and new React elements to determine what changed, then creates or updates Fibers accordingly. Present in all React versions. |
Render cycle
| Term | Definition |
|---|---|
| Render phase |
In-memory phase where React builds the workInProgress
tree. Interruptible — can be paused, resumed, or abandoned without
the user seeing anything.
|
| Commit phase | Synchronous phase where React applies all changes to the DOM. Uninterruptible and all-or-nothing — the user sees the update only after the entire commit completes. |
| beginWork | Function that processes a Fiber top-down during the render phase. Creates child Fibers and determines what work is needed on this node. |
| completeWork | Function that processes a Fiber bottom-up after its subtree is done. Creates DOM nodes (for host fibers) and bubbles effect flags up the tree. |
| Bailout | Optimization where React skips re-rendering a component because nothing relevant changed: same props, same context value, no pending lanes, no effect flags. |
Double buffering
| Term | Definition |
|---|---|
| current | The Fiber tree currently rendered on screen. Never modified during an in-progress render. |
| workInProgress | The Fiber tree being built in memory. Can be safely abandoned at any time without affecting what the user sees. |
| alternate |
Pointer connecting current ↔ workInProgress
Fibers. When a render completes, the trees swap roles via this
pointer — the mechanism behind double buffering.
|
Lanes & scheduling
| Term | Value | Definition |
|---|---|---|
| SyncLane | 0b0000000000000000000000000000001 |
Highest priority. Discrete events (click, typing), legacy mode, flushSync. |
| InputContinuousLane | 0b0000000000000000000000000000100 |
High priority for continuous user input: scroll, mousemove, drag. |
| DefaultLane | 0b0000000000000000000000000010000 |
Normal priority for most setState updates. |
| TransitionLane1 | 0b0000000000000000000000001000000 |
Low priority for non-urgent updates triggered by startTransition. |
| IdleLane | 0b0100000000000000000000000000000 |
Background work that runs only when the browser is idle. |
| OffscreenLane | 0b1000000000000000000000000000000 |
Lowest priority. Deferred and hidden work (Activity, prerendering). |
| pendingLanes | — | Bitfield on FiberRoot tracking all pending work across the app. |
| renderLanes | — | The lanes currently being processed in the active render pass. |
| childLanes | — | Bitfield on a Fiber tracking pending work anywhere in its descendants. Zero means React can skip the entire subtree. |
Suspense & Activity
| Term | Version | Definition |
|---|---|---|
| Suspense | React 16.6+ | Component that catches promise throws and shows fallback UI while waiting for async data or lazy-loaded code. |
| Activity | React 19 |
Visibility / pre-render control component. Hidden content
(mode="hidden") is deferred to OffscreenLane
with its state and DOM preserved; effects are torn down on hide and
re-run on show. Not the same as selective hydration.
|
| Offscreen | React 18+ | Internal component (tag 22) used by both Suspense and Activity for visibility control. Never used directly. |
| Hydration | React 16+ | Process of attaching React's event system and state to server-rendered HTML without recreating the DOM nodes. |
| Selective hydration | React 18+ |
Hydrating interactive or visible Suspense boundaries first,
prioritized by user interaction. Uses
SelectiveHydrationLane and Suspense boundaries —
not Activity.
|
| SuspenseException | React 18+ | The exception thrown by components when waiting for async data. Caught by the nearest Suspense boundary, which then shows its fallback. |
Hooks & state internals
| Term | Definition |
|---|---|
| memoizedState | On a Fiber: the head of the linked list of hook states for function components. On an individual Hook node: the current state value stored by that hook. |
| updateQueue | Circular linked list of pending state updates attached to a hook. Preserves all updates across interruptions so none are lost when a render is restarted. |
| baseQueue | Queue of updates that were skipped because they belonged to a lower-priority lane than the current render. Reprocessed in a future render pass. |
| baseState |
The state value that existed before the first skipped update.
Used as the starting point when reprocessing baseQueue.
|
| eagerState |
Optimization: React pre-computes the next state when a single
setState is called on an uncontested fiber, enabling an
early bailout without scheduling a render at all.
|
Effects
| Term | Definition |
|---|---|
| useEffect | Async effect that runs after browser paint. Does not block rendering or painting. |
| useLayoutEffect | Sync effect that runs before browser paint. Blocks painting. Use for DOM measurements where you need the layout to be settled. |
| Passive effect |
Internal effect flag indicating a useEffect. Scheduled
via the Scheduler and runs asynchronously after the browser has
painted.
|
| Layout effect |
Internal effect flag indicating a useLayoutEffect. Runs
synchronously inside the commit phase, before the browser paints.
|
Server-side React
| Term | Version | Definition |
|---|---|---|
| SSR | React 16+ | Server-Side Rendering. Generate HTML on the server, send to the client, then hydrate. |
| RSC | React 18+ | React Server Components. Components that execute only on the server and stream their output to the client via the Flight protocol. Cannot use hooks or browser APIs. |
| Flight protocol | React 18+ | Wire format for streaming RSC data. Row-based format where each row has a type prefix that identifies its content (component tree, client reference, error, etc.). |
| Fizz | React 18+ | React's streaming SSR renderer. Sends HTML to the browser as each piece is ready rather than waiting for the entire page. |
| hydrateRoot | React 18+ |
API to attach React to server-rendered HTML. Replaces the legacy
hydrate() call and supports concurrent features.
|
Fiber properties reference
| Property | Type | Description |
|---|---|---|
tag | number | Fiber type constant (see tag table below) |
type | any | Component function / class or DOM tag string |
stateNode | any | DOM node (HostComponent), class instance (ClassComponent), or FiberRootNode (HostRoot) |
return | Fiber | Parent Fiber (named "return" because execution returns here after finishing the subtree) |
child | Fiber | First child Fiber |
sibling | Fiber | Next sibling Fiber (forms a linked list, not nesting) |
lanes | number | Bitfield of pending work scheduled on this Fiber |
childLanes | number | Bitfield of pending work anywhere in descendants |
flags | number | Side-effect flags on this Fiber (Placement, Update, Deletion, …) |
subtreeFlags | number | OR of all descendants' flags — lets React skip clean subtrees in O(1) |
Common Fiber tags
| Tag | Name | Description |
|---|---|---|
| 0 | FunctionComponent | Function component |
| 1 | ClassComponent | Class component |
| 3 | HostRoot | Root of the Fiber tree; stateNode points to FiberRootNode |
| 5 | HostComponent | DOM element (div, span, etc.) |
| 6 | HostText | Text node |
| 7 | Fragment | React.Fragment / <></> |
| 11 | ForwardRef | React.forwardRef component |
| 12 | Profiler | React.Profiler |
| 13 | SuspenseComponent | Suspense boundary |
| 14 | MemoComponent | React.memo component (with custom compare fn) |
| 15 | SimpleMemoComponent | Optimized memo (no custom compare fn) |
| 22 | OffscreenComponent | Internal visibility controller used by Suspense and Activity |
| 31 | ActivityComponent | Visibility / pre-render control (React 19); defers hidden content to OffscreenLane |