Understand Atomico's virtual DOM rendering engine: createElement, render, Fragment, Mark, and reconciliation. Triggers when the user needs to understand how Atomico renders, how keyed reconciliation works, how moveBefore is used for DOM reordering, or how the render pipeline (hooks → render → effects) operates. Also covers utilities like createRef, className, and delegateValidity.
Each Atomico component follows this render cycle:
1. connectedCallback (mount)
2. component render function executes
3. useInsertionEffect callbacks fire
4. Virtual DOM diff → DOM mutations
5. useLayoutEffect callbacks fire
6. (microtask boundary)
7. useEffect callbacks fire
prop change / setState / useUpdate()
→ this.update() called
→ await mounted promise
→ hooks.render(this._render)
→ hooks.dispatch(INSERTION_EFFECT)
→ render(result, this, this.symbolId)
→ hooks.dispatch(LAYOUT_EFFECT)
→ await microtask
→ hooks.dispatch(EFFECT)
createElement / — Create Virtual NodeshThe function underlying JSX transformation.
import { createElement, h } from "atomico";
// These are equivalent:
const vnode1 = createElement("div", { class: "card" }, "Hello");
const vnode2 = h("div", { class: "card" }, "Hello");
const vnode3 = <div class="card">Hello</div>; // JSX
{
type: "div" | Constructor | Node,
props: { ... },
key: any
}
When children have key props, Atomico uses keyed reconciliation:
{items.map((item) => (
<li key={item.id}>{item.name}</li>
))}
Map<key, ChildNode>moveBefore (if available) to preserve internal state
(focus, scroll position, etc.)Without keys, Atomico uses positional matching and replaces nodes in-place.
moveBefore APIAtomico detects browser support for moveBefore and uses it for keyed list
reordering. This preserves:
<video>/<audio> playback stateFragmentGroups children without adding a DOM wrapper:
import { Fragment } from "atomico";
<Fragment>
<p>First</p>
<p>Second</p>
</Fragment>
Mark — Internal Fragment BoundaryMark extends Text — used internally to delimit fragment boundaries in the
DOM. The renderChildren algorithm uses Mark instances as sentinels.
Note:
Marknodes are filtered out byuseSlotanduseNodeshooks automatically. You should never need to create or interact with them directly.
render — Mount VNodes to DOMThe imperative render function for mounting virtual DOM trees:
import { render, createElement } from "atomico";
render(
createElement("host", { children: "Hello" }),
document.getElementById("app")
);
Every Atomico element instance has these special properties:
| Property | Type | Description |
|---|---|---|
updated | Promise<void> | Resolves after the current render cycle |
update() | () => void | Triggers a re-render |
symbolId | Symbol | Unique render ID for the instance |
const el = new MyComponent();
document.body.appendChild(el);
await el.updated;
// DOM is now fully rendered
createRefCreates a ref object { current: T }:
import { createRef } from "atomico";
const ref = createRef<HTMLElement>();
ref.current; // HTMLElement | undefined
className (from atomico/utils)Concatenates class names, filtering falsy values:
import { className } from "atomico/utils";
className("base", isActive && "active", isLarge && "large");
// "base active" (if isActive is true, isLarge is false)
delegateValidity (from atomico/utils)Extracts validity state from a native input for use with useFormValidity:
import { delegateValidity } from "atomico/utils";
const result = delegateValidity(inputElement);
// { valid, message, valueMissing, tooShort, ... }
When setting properties on DOM nodes, Atomico follows this priority:
shadowDom, staticNode, cloneNode, children, key: Internal props, not
applied to the DOMon* handlers: Registered as event listeners with event delegationref: Applied as .current = node or called as functionstyle: Applied as object (per-property) or string (cssText)assignNode on <slot>: Calls slot.assign(node) in a task queue$-prefixed: Always set as attributes (forces attribute mode)list, type, size, form, width, height, src, href, slot
checked, value, selected — values are read from the DOM node before
comparison to detect external mutations.