A Web Worker has no DOM, and React and Preact build their output by calling document.createElement, insertBefore and setAttribute. None of those exist in a worker.
Isoloop is my open-source toolkit for running the parts of an app on workers, a part being one piece of the app, such as a widget. This article is about the piece that gives a worker a DOM anyway, the render bridge, and about the choices behind it. The bridge doesn't care what fills that DOM: React, Preact or code that calls the DOM directly. React and Preact are the two frameworks it was sized against.
What was considered first
The first plan was to adopt Shopify's Remote DOM, which already puts a DOM in a worker and records mutations. Isoloop's first design put it behind an interface so it could be swapped out, with a one-evening spike as the gate: could its mutation records be plain data, and could Isoloop give nodes its own ids and intercept listeners?
The spike passed. Rendering Preact 11 and React 19 into Remote DOM (1.12.1, polyfill 1.7.0) still showed what adopting it meant:
- no
element.style, which both frameworks need; - element properties like
valueandcheckednever leave the worker; - no
HTML*Elementclasses, and React's commit phase checksinstanceof HTMLIFrameElement; - a move is a remove plus a re-insert of the whole serialized subtree;
- listeners and properties go through hooks you fill in yourself, for every element;
- the page-side receiver is deprecated, so Isoloop would write the page half anyway.
That adds up to about 7,000 lines of dependency (about 4,270 in the polyfill and 2,690 in the core package), with those gaps to patch around it. The spike's logs showed the two frameworks need about 30 DOM members, and a bridge for exactly that subset was estimated at about 1,450 lines.
Two other routes were weighed. Remote DOM's polyfill alone, with Isoloop's own records, would keep the largest part of the dependency and the style, property and class gaps. A virtual-DOM renderer with no DOM in the worker would need a reconciler per framework, which is more code than the subset.
So Isoloop writes its own, with no dependencies, and grows it only on evidence: a member is added when a conformance case, an adapter test or a real app needs it, and each one comes with a test.
The idea: render into a fake DOM, send the changes
The framework doesn't need a real DOM. It needs an object that answers the DOM calls it makes. So the worker gets a small DOM subset installed as document, and every change the framework makes to it is recorded as plain data. Once per microtask, the recorded batch is posted to the page, where a piece of code called the applier applies it to the real DOM.
What the records look like
A batch is an array of tuples, one per change. Isoloop's bridge, format isoloop-dom@1, has these:
type Batch = Change[]; type Change = | ['insert', parentId, node, beforeId | null] // node is a new subtree | ['move', parentId, nodeId, beforeId | null] | ['remove', nodeId] | ['text', nodeId, data] | ['attr', nodeId, name, value | null] | ['prop', nodeId, name, value] | ['listen', nodeId, type, on]; That's a sketch of the shape, not the package's exact types.
A move is one record. When a keyed list reorders, an existing node moves with a single move. It isn't removed and inserted again as a new subtree, so it keeps its identity on the page, and with it focus.
Functions never cross. A component's onClick stays in the worker, and what travels is a listen record: "node 12 wants click". The page listens once per surface, the shadow-DOM host where a part renders. When the event fires, the page sends a plain description of it back, and the worker dispatches it to the node, with capture and bubble running inside the worker.
The page decides what gets created. Every tag, attribute and URL goes through an allow-list before it becomes a real node. An unknown tag becomes a div, and script, iframe and style elements and on* attributes are never created. Inputs are owned by the page, so a value from the worker doesn't overwrite what the user is typing in a focused field unless the component forces it. Since 0.1.1, the page writes a style attribute as el.style.cssText instead of with setAttribute('style', …). The Content Security Policy directive for styles, style-src, doesn't govern that write, so a page with surfaces runs under style-src 'self' with no 'unsafe-inline'. Vite's dev server still needs 'unsafe-inline' for its own <style> elements.
How little of the DOM the frameworks use
To find out what the frameworks call, wrap every member of the subset, put a Proxy under the prototypes so a lookup that finds nothing is recorded too, run a fixture app on each framework version and commit the log. A test then fails if a framework starts reaching for something the subset lacks.
Those logs list between 22 Class.member entries (Preact 10) and 43 (React 19) per framework version. The logs and smoke tests also turned up an odd corner: React checks 'oninput' in document when it loads, and without that, typing never fires onChange. So the subset has to be installed before the app's module is imported.
Keeping the two halves apart
The worker half and the page half must agree on one format, so they live in one package, @isoloop/dom, with separate entry points for the worker, the page and the tests. Each half is type-checked with its own lib setting, so a stray document in the worker half fails the build. The package is internal: app code never imports it.
Both halves ship in the app's build, so an exact match of the format version is enough, with no range to support. A mismatch fails the part at start-up and doesn't restart it, since a restart can't change the outcome.
Several widgets in one worker
A worker has one global document. When several visual parts share a worker (a pool), the bridge keeps that document and gives each part its own root element. Records go out per part, tagged with the part, and moving a node from one part's root into another's throws. The page keeps one applier per surface and sees nothing different.
In a prototype on 2026-11-09, 8 light React widgets in one worker used 35% (Chromium), 64% (Firefox) and 50% (WebKit) less memory than 8 workers of their own. The widgets were fed at the data rate of Isoloop's plant dashboard (vibration in 50 ms chunks at 1 kHz, slow signals every 200 ms), with medians of 7 runs, each in a fresh browser. They ran under Playwright 1.64.1 on Linux (WSL2, 32 cores, no GPU), in Chromium 156, Firefox 157 and WebKit 27.2 (benchmark).
The p95 time from publish to patch stayed within a few tenths of a millisecond of the separate workers', though the bench measures to the frame and can't show sub-frame differences. The prototype lacked the runtime, supervision and per-part record routing a real pool adds. Widgets built together share one React instance, and widgets built apart save less. Heavier widgets in one worker delay each other, and they can read each other's DOM and input, so widgets that handle secrets stay on their own worker.
What it costs
The bridge lets code render from a worker, and it doesn't make the rendering free.
- DOM updates still land on the main thread. Isoloop moves the computation off it, and one thread per document still applies every change.
- Input arrives a moment later. The page forwards a fixed list of events, and only to nodes that listen for them. Other events, such as drag and drop, wheel, copy and paste and IME composition, never reach the worker.
preventDefault()comes too late, because the page has already acted. In Chromium, a worker's reply to an input waits until after the next frame. In the markets dashboard, one of Isoloop's example apps, at its Heavy size, that came to about 30 ms of typing latency in every Isoloop build of it, against 5 to 10 ms for the native build, on Chromium and WebKit (Playwright 1.64.1, 32-core WSL2 machine, 2026-11-08, limits guide). - There is no layout in the worker.
getBoundingClientRect,offsetWidth,getComputedStyleand the like throw aNotSupportedErrorthat names what to use. Asking the page (measure,focus,scrollIntoView) is asynchronous. A library that measures on every render needs rewriting or belongs on the page. - Other members outside the subset are absent and throw when called, and nothing in the worker parses HTML (
innerHTML) or clones nodes (cloneNode) yet, which template-cloning frameworks and some libraries need.
The render bridge's code is the @isoloop/dom package: https://github.com/isoloop/isoloop/tree/main/packages/dom
Written with the help of AI; facts checked against the linked sources.


