Overview
TheVirtualDom is the core engine that manages component state, tracks updates, and generates mutations for renderers. It implements a concurrent, async-aware virtual DOM with support for suspense, error boundaries, and efficient diffing.
VirtualDom Structure
Creating a VirtualDom
Basic Creation
With Props
Prebuilt VirtualDom
With Root Context
Rendering
Initial Render
Render to Vec
In-place Rebuild
Update Cycle
Immediate Rendering
Render to Vec
Event Loop
A complete event loop integrating VirtualDom with a renderer:Suspense
Wait for Suspense
Check Suspended Tasks
Render During Suspense
Scope Management
Access Scopes
Mark Dirty
Run in Runtime Context
Run in Scope
Context Injection
Provide Root Context
Runtime Access
Diffing Algorithm
The VirtualDom uses an efficient diffing algorithm that:- Templates are compared by pointer - Static templates are only created once
- Dynamic nodes are diffed recursively - Only changed parts update
- Keys enable list optimization - Reordering lists is efficient
Example: List Diffing
Mutations
TheMutations struct contains the list of edits to apply:
Processing Mutations
Advanced Features
Process Events
Wait for Work
Check for Dirty Scopes
Testing
Async Testing
Performance
Memoization
Keys for Lists
See Also
- Component - Creating components
- Element - Virtual nodes
- Scope - Component context
- VirtualDom Guide