← back to index.html · Next: WC + Server Morph Synergy →
Standalone Web Components in dmax
Zero-JS HTML templates, reactive typed attributes (:num, :bool, :json), automatic wc.* signal inference, shared adoptedStyleSheets, Declarative Shadow DOM hydration, and form-associated Shadow inputs — plus why Tier 3 features are intentionally skipped.
1. Zero-JS Light-DOM Component + wc.* Auto-Inference
Defined solely with <template data-m-wc="dm-counter" data-m-wc-props="count:num step:num label">. Expressions referencing wc.count and wc.step auto-subscribe to @_wc.* with zero manual triggers. Sibling hosts stay isolated, and mutating attributes via DOM updates _wc live.
2. Shadow DOM Copy Button (Shared adoptedStyleSheets)
Declared via <template data-m-wc^dom.open="dm-copy-btn">. The <style> block is compiled once into one shared CSSStyleSheet adopted by every instance (zero per-instance style parsing), while CSS custom properties pass themes through the shadow boundary.
3. Declarative Shadow DOM (DSD) Hydration
The card below ships with an SSR <template shadowrootmode="open"> already attached before JS runs. When dm-dsd-card upgrades, dmax detects the existing shadowRoot, skips cloning the client template (zero duplication / zero FOUC), and wires the server-rendered directives in place.
4. Form-Associated Shadow Input (formAssociated + delegatesFocus)
Light-DOM components work in native <form> for free. When a component genuinely needs Shadow DOM encapsulation and form submission, opt in with { mode: 'open', delegatesFocus: true, formAssociated: true }.
5. Why We Intentionally Skip Tier 3 (Design Boundaries)
Every feature below was evaluated against Lit, Datastar Rocket, and Enhance and deliberately kept out of dmax core. Keeping them out keeps dmax small (~18 KB gz), zero-build, and hypermedia-first:
| Skipped Tier 3 idea | Why we do not build it | Optimal dmax pattern instead |
|---|---|---|
JS render() / VDOM / tagged templates (Lit) |
Duplicates HTML parsing and drags in a JS-first templating engine that fights server-rendered HTML and CSP nonces. | Server renders HTML (or <template data-m-wc> + data-m-it for local client lists) and dmax morphs in place. |
| 11-type attribute schema / reflection DSL | Reflecting every internal signal back to DOM attributes causes attribute thrashing and doubles morph diff cost. | 4 coercers (string, :num, :bool, :json) cover 99% of HTML attrs; pass rich objects via JS props (data-m-ex:.cfg@chart). |
| Shadow DOM by default (Rocket / Lit) | Breaks page stylesheets, native <form> participation, global a11y aria-controls/for IDs, and adds overhead when encapsulation isn't needed. |
Light DOM by default; opt into ^dom.open / ^dom.closed only for self-contained widgets (dm-copy-btn, dm-style-panel). |
| Wrapping server-rendered lists / rows in WCs | Custom element upgrade + lifecycle hooks per row hurt large-list morph latency and memory. | Plain HTML elements + scoped <li data-m-si:_wc='{open:false}'> give per-row wc.* reactivity with zero custom-element overhead. |
data-m-si:_wc + data-m-sh^hidden):