Skip to content

Commit 58ede4e

Browse files
committed
The VDOM Revolution: How We Render UIs from a Web Worker #7168 WIP
1 parent 9f67144 commit 58ede4e

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

learn/blog/v10-deep-dive-vdom-revolution.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ abstraction and work directly with **JSON Blueprints**. This is the "native lang
5858

5959
The component's `render()` method returns a structured JSON object that describes the VDOM tree.
6060

61+
We've seen this movie before. In the world of APIs, the verbose, heavyweight XML standard was supplanted by the lighter,
62+
simpler, and more machine-friendly JSON. We believe the same evolution is inevitable for defining complex UIs.
63+
6164
This approach has profound advantages:
6265

6366
* **Extreme Data Efficiency:** A JSON blueprint is drastically smaller than its equivalent rendered HTML.
@@ -139,6 +142,14 @@ Enabling this superior rendering engine is as simple as setting a flag in your p
139142
}
140143
```
141144

145+
But its real genius lies in how it handles complex insertions. The `insertNode` delta does not contain a VNode for the
146+
*entire* new fragment. Instead, the VDOM worker's `DomApiVnodeCreator` utility generates a **pruned VNode tree**. This
147+
tree intelligently omits any nodes that are simply being *moved* into the new fragment.
148+
149+
This means the renderer only creates DOM elements for truly new nodes. Existing nodes are handled by separate,
150+
efficient `moveNode` deltas. It's a powerful optimization that prevents the renderer from wastefully creating DOM that
151+
already exists elsewhere on the page.
152+
142153
#### For Modifying Existing DOM: Surgical Updates
143154

144155
When you change a property on an existing component—like its text, style, or attributes—the VDOM worker sends different
@@ -186,6 +197,17 @@ Here's how it works:
186197
The VDOM worker receives this pre-optimized, asymmetric blueprint. When it sees a `neo-ignore` node, it completely
187198
skips diffing that entire branch of the UI.
188199

200+
#### Inside the VDOM Worker: The Diffing Engine
201+
Once the optimized blueprint arrives at the VDOM worker, the second half of the revolution begins. Here, the plain JSON
202+
blueprint is inflated into a tree of `VNode` instances. This is a key architectural point: the `VNode` is a very
203+
lightweight wrapper class that exists *only* inside the VDOM worker. It performs no complex logic, but normalizes the
204+
raw JSON blueprint, ensuring every node has a consistent structure (e.g., an `id` and a `childNodes` array) for the
205+
diffing engine to process reliably.
206+
207+
The `vdom.Helper` singleton then acts as the core diffing engine. It compares the new `VNode` tree to the previous one
208+
and, instead of generating HTML, produces an array of **deltas**—highly specific, low-level instructions for the main
209+
thread to execute.
210+
189211
It’s the ultimate optimization: instead of sending the entire blueprint for a skyscraper just to fix a window,
190212
we now send the floor plan for the lobby *and* the specific blueprint for that one window on the 50th floor,
191213
ignoring everything else in between. As a developer, you don't do anything to enable this. You simply change state,

0 commit comments

Comments
 (0)