Browse by type
learn to build a custom react renderer

Please ★ this repo if you found it useful ★ ★ ★
Built against react 19 and react-reconciler 0.33.
DISCLAIMER: These definitions are not official. They are based on my own understanding of react renderers. They are not intended for understanding how to use react, but rather are for providing the context of understanding how a react renderer works.
The video and the slides were recorded against react 16, so some method names differ from the current code. The concepts are unchanged; see the notes below for what moved.
BitSpur offers premium Node and React development and support services. Get in touch at bitspur.com.
make prepare # one time machine setup (asdf toolchain + pnpm install)
or, if you already have node and pnpm
pnpm install
make build # typecheck every phase
make test # run every phase's tests with coverage
make lint # oxfmt --check + oxlint
make format # format with oxfmt
Run a phase's demo from inside the phase
cd phaseA
pnpm start
The diagram represents the following code
<Form>
<Button />
<Input />
</Form>

A tree structure that represents the current rendered state. Every branch and leaf on the tree is either a component or element.
Reconciliation is the process of determining which parts of the virtual dom need to be changed by diffing the current virtual dom tree with the new virtual dom tree.
The reconciler is the bindings to the react reconciliation lifecycle methods. This is NOT the react lifecycle hooks even though it is closely related to the react lifecycle hooks.
A fiber is a virtual stack frame of work for the react reconciler. You can think of it as the low level api the reconciler is built on top of.
A node is the interface of the renderer that the react renderer is binding to. For example
window.document would be the node used in a react renderer that binds to the dom.
The root node is the node used in the top of the react virtual dom tree.
You can think of an element as a react component that is directly bound to the reconciliation lifecycle methods. This is NOT the same thing as a react component, although it can be used like a react component. Because it is directly bound to the react reconciliation lifecycle methods it is more powerful, but also more complex. Elements form the foundation that all react components are built on top of.
`
,and
The base element is the element all other elements inherit from.
An encapsulation of components and/or elements.
The root element is the element used in the top of the react virtual dom tree. This element is not created with JSX but is initialized during the initial render.
This represents the root of the react virtual dom tree.
The reconciler api changed significantly since this tutorial was first recorded. The important differences baked into the phases are listed below.
prepareUpdate was removed. commitUpdate now receives the old and new props directly instead of
an update payload.
commitUpdate(
instance: Instance,
type: Type,
oldProps: Props,
newProps: Props,
internalHandle: any,
): void {
return instance.commitUpdate(newProps);
}
scheduleDeferredCallback, cancelDeferredCallback, shouldDeprioritizeSubtree and now are gone.
The host config instead tracks an update priority for react.
setCurrentUpdatePriority(newPriority: number): void {
currentUpdatePriority = newPriority;
},
getCurrentUpdatePriority(): number {
return currentUpdatePriority;
},
resolveUpdatePriority(): number {
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
return DefaultEventPriority;
},
React 19 only exposes concurrent roots, so a renderer that wants a synchronous render (like this
one) creates the container with ConcurrentRoot and drives the work to completion itself.
const root = reconciler.createContainer(
rootElement,
ConcurrentRoot,
null, // hydration callbacks
false, // strict mode
null, // concurrent updates override
"create_react_renderer_", // identifier prefix
(error: Error) => {
throw error; // onUncaughtError
},
(error: Error) => console.warn(error), // onCaughtError
(error: Error) => console.warn(error), // onRecoverableError
() => undefined, // onDefaultTransitionIndicator
);
reconciler.updateContainerSync(element, root, null, () => undefined);
reconciler.flushSyncWork();
The host config must also implement microtask scheduling (supportsMicrotasks +
scheduleMicrotask), transition support (NotPendingTransition, HostTransitionContext,
shouldAttemptEagerTransition), the suspense commit hooks (maySuspendCommit, preloadInstance,
startSuspendingCommit, suspendInstance, waitForCommitToBeReady) and a handful of instance
hooks (getInstanceFromNode, getInstanceFromScope, detachDeletedInstance, ...). These exist as
logged stubs from phaseA so every phase renders under react 19.
setup the reconciler
create some custom elements
bind some custom elements to reconciler
setup node
bind base element lifecycle methods
bind critical element lifecycle methods to reconciler lifecycle methods
create base elements
create text bindings
finish reconciler bindings
add default props
add options
create components
Try to start small. Build your renderer in many layers of abstraction. This renderer uses the following layers of abstraction.
reconciler <- BaseElement <- elements <- components <- more components
Elements are hard to build and hard to debug. It's best to have a few broad and general elements and then build lots of specific components on top of the broad elements.
This can catch lots of unnecessary bugs.
Understanding the react lifecycle can really help with debugging.
You can get access to the node data from a ref. For example, the following will log the data
from the node used in the <Smart /> element. This is very helpful because the ref runs
before the entire render cycle is finished. This is helpful for debugging bugs that are
preventing rendering from finishing.
<Smart code="const hello = 'world'" ref={(ref: any) => console.log(ref.node)} />
This only works on element refs. Since elements are abstractions of your nodes, you can't see the value of nodes in component refs.
For example, the following would log undefined
<FunctionDeclaration name="hello" ref={(ref: any) => console.log(ref.node)} />
browse all types & interfaces →
$ claude mcp add create-react-renderer \
-- python -m otcore.mcp_server <graph>