VDOM & Rendering Engine
Tairitsu's Virtual DOM is a platform-agnostic rendering engine. It can drive browser DOM, server-side HTML strings, or any custom render target — all through a trait-based Platform abstraction.
Architecture
mermaid
VNode Types
rust
1
2
3
4
5
VElement
rust
1
2
3
4
5
6
7
8
9
The Render Cycle
- 1Component renders → produces a VNode tree via rsx!
- 2Signal changes → component re-renders → produces new VNode tree
- 3Diff — compares old tree against new tree, produces a list of Patch operations
- 4Apply patches — calls into the Platform trait to execute DOM mutations
- 5Repeat — on next signal change
mermaid
Patch Operations
rust
1
2
3
4
5
6
7
8
9
10
11
Diff Algorithm
The diffing engine (packages/vdom/src/diff.rs) compares two VNode trees node-by-node:
mermaid
Keyed Child Diffing (planned)
For lists of elements with unique keys:
rust
1
2
3
4
5
6
7
rsx!
The keyed diff algorithm identifies insertions, deletions, and moves — minimizing DOM mutations.
Platform Trait
The Platform trait abstracts all DOM operations behind 14 sub-traits:
rust
1
2
3
4
5
6
DomOps (the core sub-trait)
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Platform Implementations
| Implementation | Target | Purpose |
|---|---|---|
| WitPlatform | wasm32-wasip2 in browser | Uses WIT bindings → browser-glue → DOM |
| SsrPlatform | Native (server) | Renders to HTML string buffer |
| WebPlatform | wasm32-unknown-unknown | Uses web-sys (legacy compat) |
| TestPlatform | Native (tests) | Records DOM mutations for assertions |
Event System
34+ typed event types with automatic downcast:
rust
1
2
3
4
5
6
7
8
9
10
11
// Type-safe convenience methods
element
.on_click
.on_keydown
.on_submit
.on_touchstart;
// Generic handler with manual downcast
element.on_event;
Reactive Signals
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Create a signal
let count = new;
// Read (subscribes current component)
let value = count.get;
// Write (triggers re-render for all subscribers)
count.set;
// Effect (automatically re-runs when dependencies change)
create_effect;
// Standalone signal (outside component lifecycle)
let shared = new;
Scheduler
The scheduler (packages/vdom/src/runtime.rs) coalesces multiple signal updates into a single render pass:
mermaid
This is similar to React's automatic batching or microtask-based scheduling in Vue 3.