Browser experiments & working notes
Renderer examples / Stencil
Compiled JSX.
Native targets.
Custom elements compiled from Stencil components with reactive properties and Shadow DOM.
for="host"#controlWaiting for Stencil to render…
Browser details
- Current path
- Checking browser support…
- Native API surface
- Checking…
- Active adapters
- Waiting for setup…
Automatic checks for the native property. Force fallback loads the selected adapters. Browser alone leaves them out.
Labels & rendering
A new control. The same reference.
The outside label references the component. Stencil renders the checkbox inside its shadow root.
Try: Click the label, replace the checkbox, then click the label again. Each replacement starts unchecked.
Popover targeting
An outside button. A rendered panel.
Stencil creates a native popover inside another component. The outside buttons reference its host.
Try: Open the popover, then dismiss it with its close button or Escape.
Open an internal popover
How the examples are connected
Each component sets its shadow root’s referenceTarget to the internal target ID. The fallback loads before the component definitions, so it can capture the roots when the renderer creates them and observe later DOM changes.
The page waits for the renderer’s first update before enabling its buttons. Replacing the checkbox changes the component’s revision attribute; the renderer creates a new input with the same ID.
<label for="renderer-checkbox">Send me release notes</label>
<rt-stencil-checkbox id="renderer-checkbox" revision="0"></rt-stencil-checkbox>
<button type="button" popovertarget="renderer-popover">Open popover</button>
<rt-stencil-popover id="renderer-popover"></rt-stencil-popover>
The selected setup uses labels({ activation: "focus-and-click", naming: true }) and popoverTargets(). The page’s event listeners only display state; they do not forward label or popover actions.
Component source
src/components/checkbox.tsx
import { Component, Element, Fragment, h, Prop } from "@stencil/core";
@Component({
tag: "rt-stencil-checkbox",
shadow: true,
styleUrl: "../../../shared/components.css",
})
export class StencilCheckbox {
@Element() host!: HTMLElement;
@Prop() revision: number = 0;
componentDidLoad() {
const root = this.host.shadowRoot as ShadowRoot & { referenceTarget: string };
root.referenceTarget = "control";
this.host.setAttribute("data-renderer-ready", "");
this.host.dispatchEvent(new CustomEvent("renderer-ready"));
}
render() {
return (
<Fragment>
<div class="component-preview">
<input key={this.revision} id="control" type="checkbox" data-revision={this.revision} />
<span aria-hidden="true">Native checkbox</span>
</div>
<p class="hint">Render revision {this.revision}</p>
</Fragment>
);
}
}
src/components/popover.tsx
import { Component, Element, h } from "@stencil/core";
@Component({
tag: "rt-stencil-popover",
shadow: true,
styleUrl: "../../../shared/components.css",
})
export class StencilPopover {
@Element() host!: HTMLElement;
componentDidLoad() {
const root = this.host.shadowRoot as ShadowRoot & { referenceTarget: string };
root.referenceTarget = "panel";
this.host.setAttribute("data-renderer-ready", "");
this.host.dispatchEvent(new CustomEvent("renderer-ready"));
}
render() {
return (
<div id="panel" popover="auto" role="dialog" aria-labelledby="panel-title">
<p class="eyebrow">Stencil component</p>
<h2 id="panel-title">Rendered with Stencil</h2>
<p>This native popover lives inside a Stencil component’s shadow root.</p>
<button type="button" popoverTarget="panel" popoverTargetAction="hide" autoFocus>Close popover</button>
</div>
);
}
}
components.js
import { defineCustomElements } from "../../dist/stencil/index.js";
import { whenRendererEvent } from "../shared/renderer-readiness.js";
defineCustomElements();
// dist-custom-elements does not expose componentOnReady(); wait for the
// componentDidLoad lifecycle instead of guessing how many frames rendering takes.
export async function whenReady() {
const hosts = ["renderer-checkbox", "renderer-popover"].map(id => {
const host = document.getElementById(id);
if (!host) throw new Error(`Missing Stencil demo host: ${id}`);
return host;
});
await Promise.all(hosts.map(host => whenRendererEvent(host, "Stencil")));
}
Functional JavaScript sizes
Functional page JavaScript
27.767 KB 10.444 KB gzipAlways loaded.
Fallback additional
23.929 KB 8.430 KB gzipCore + selected adapters.
Fallback route total
51.696 KB 18.874 KB gzipAlways-loaded and fallback files; shared files counted once.
Native-surface route total
28.756 KB 10.982 KB gzipIncludes 0.989 KB (0.538 KB gzip) of behavioral probes requested only after the property surface is present.
Minified / gzip. 1 KB = 1,000 bytes. Demo-only syntax highlighting is excluded from the functional totals and reported separately below.
Whole-page delivery context
HTML document
19.226 KB 1 requestGenerated markup, including these measurements.
Initial supporting assets
18.520 KB raw 17.897 KB local transfer · 3 requestsStyles, icon, and the highlighting scheduler; functional JS is separate above.
Initial page with fallback
89.442 KB raw 55.997 KB local transfer · 9 requestsDocument + functional fallback path + initial supporting assets, with unique files counted once.
Deferred highlighting
18.671 KB raw 8.581 KB local transfer · 10 requestsEngine, theme, and this page’s grammar closure, requested after a source disclosure opens or during idle time.
“Local transfer” matches the included development server: gzip JavaScript sidecars, but uncompressed HTML, CSS, and SVG. GitHub Pages, browser caching, HTTP headers, and production compression can change transferred bytes and request scheduling. Module preloads fetch functional modules early without evaluating the app and do not add duplicate transfers.
Inspect the 6 generated JavaScript files
Selected adapters: labels, popover-targets.
Gzip totals sum each compressed file. The fallback and native-probe routes are mutually exclusive. Separate CSS files, HTML, JSON, source maps, HTTP headers, and Microlighter assets are excluded. Component styles embedded in JavaScript are included. Transfer sizes depend on compression and caching. Microlighter MIT license.
| File | Delivery | Minified | Gzip |
|---|---|---|---|
shared/chunks/app-22WHH5BU.js |
Page | 24.368 KB | 8.954 KB |
shared/chunks/chunk-CLCOZ6O7.js |
Fallback / native probe shared | 0.849 KB | 0.422 KB |
shared/chunks/chunk-S2QLMWTP.js |
Page | 0.142 KB | 0.138 KB |
shared/chunks/detect-X6QVIAY4.js |
Native-surface probe | 0.140 KB | 0.116 KB |
shared/chunks/reference-target.setup-F3BB382F.js |
Fallback additional | 23.080 KB | 8.008 KB |
stencil/main.js |
Page | 3.257 KB | 1.352 KB |
Renderer integration & limitations
Stencil and Reference Target
Stencil compiles the TypeScript and JSX into custom elements during the example build. Each component sets referenceTarget in componentDidLoad, and the page waits for that lifecycle before enabling its controls. A keyed input is replaced when the revision prop changes.
The library and its component code are included in Page JavaScript above. Each renderer is built as an independent page with only the labels and popover-targets adapters in its optional fallback bundle.
These examples use open, client-rendered roots. They do not test server rendering or hydration. The label fallback does not recreate native label.control or input.labels relationships. Readouts describe DOM state; computed names and assistive technology need separate validation.