Overview
A lazy component is an async function (or Promise/thenable) that resolves to a Component — or a module with a default export that is a Component. Pass it to x() exactly like an eager component: x(async () => import('./Heavy'), props).
When x() receives an async loader, Mates calls isAsyncValue, tears down any currently mounted view immediately (so the old page does not linger), then resolveAsyncValue → unwrapModule and assigns the sync Component. While loading, the host renders empty.
isXViewTemplate(value) returns true for TemplateResults produced by x() / view() / template() (branded with a shared Symbol). Useful for SSR helpers and tooling that must distinguish component embeddings from plain html results.
Eager vs lazy vs manual atom swap
|
Pattern
|
API
|
When
|
|---|---|---|
| Eager |
x(Comp, props)
| Default — component already in the bundle. |
| Lazy (built-in) |
x(async () => import(…), props)
|
Code-split at the import boundary. Same API as eager x().
|
| Manual swap |
atom + x(Comp(), {})
| Store a resolved constructor yourself — fine for demos; prefer LazyComponent for real splits. |
| Router |
component: async () => import(…)
|
Same lazy resolution path as x().
|
Lazy load with x()
Click Load chart — x(loadChart) detects the async function, waits, unwraps { default: Chart }, then mounts with props. In production, use async () => import('./Chart').
Swap lazy views + isXViewTemplate
Switching A/B tears down the previous view immediately and starts a new resolve. isXViewTemplate(x(...)) is true — plain html`...` is false.