Skip to content

ShadowDOM support - #21595

Open
NullVoxPopuli wants to merge 1 commit into
mainfrom
nvp/shadow-dom
Open

NullVoxPopuli wants to merge 1 commit into
mainfrom
nvp/shadow-dom

Conversation

@NullVoxPopuli

@NullVoxPopuli NullVoxPopuli commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Previously: #21217

Part of #20644

Fixes: #20642

Fixes: #20641

Related:

Not fixed here:

Browser Behavior (JSBin)

template + shadowrootmode

Demo
image

In-element

Demo
image

for fun, this is how small I could make the demo

Runnable here

import { template } from '@ember/template-compiler';
import { trackedObject } from '@ember/reactive/collections';

const a = trackedObject({ count: 0, increment: () => a.count++ });
const b = trackedObject({ count: 0, increment: () => b.count++ });

function shadow(mode) {
  const host = document.createElement('div');
  const shadowRoot = host.attachShadow({ mode });
  return { host, shadowRoot };
}

const shadowOpen = shadow('open');
const shadowClosed = shadow('closed'); 

<template>
  {{shadowOpen.host}}
  
  {{#in-element shadowOpen.shadowRoot}}
    <p>You have clicked the button {{a.count}} times.</p>
    <button type="button" onclick={{a.increment}}>Click</button>
  {{/in-element}}

  {{shadowClosed.host}}
  
  {{#in-element shadowClosed.shadowRoot}}
    <p>You have clicked the button {{b.count}} times.</p>
    <button type="button" onclick={{b.increment}}>Click</button>
  {{/in-element}}
</template>;

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

📊 Size report

Tarball size — 1.2 MB → 1.2 MB

dist/dev   0.1%↑

File Before (Size / Brotli) After (Size / Brotli)
./packages/shared-chunks/api-{hash}.js 27 kB / 6.1 kB 10%↑29.7 kB / 13%↑6.9 kB
./packages/shared-chunks/rehydrate-{hash}.js 15.5 kB / 3.1 kB 1%↑15.7 kB / 2%↑3.2 kB
Total (Includes all files) 2.1 MB / 514.6 kB 0.1%↑2.1 MB / 0.2%↑515.5 kB

dist/prod   0.2%↑

File Before (Size / Brotli) After (Size / Brotli)
./packages/shared-chunks/api-{hash}.js 26.5 kB / 6 kB 10%↑29.2 kB / 14%↑6.8 kB
./packages/shared-chunks/cache-{hash}.js 697 B / 258 B 2,010%↑14.7 kB / 1,490%↑4.1 kB
./packages/shared-chunks/rehydrate-{hash}.js 15.5 kB / 3.1 kB 1%↑15.7 kB / 2%↑3.2 kB
Total (Includes all files) 1.9 MB / 471.4 kB 0.2%↑2 MB / 0.2%↑472.4 kB

smoke-tests/v2-app-template/dist   0.3%↑

File Before (Size / Brotli) After (Size / Brotli)
./assets/main-{hash}.js 319.8 kB / 85.7 kB 0.3%↑320.8 kB / 0.2%↑85.9 kB
Total (Includes all files) 353 kB / 96.4 kB 0.3%↑353.9 kB / 0.2%↑96.6 kB

smoke-tests/v2-app-hello-world-template/dist   0.7%↑

File Before (Size / Brotli) After (Size / Brotli)
./assets/main-{hash}.js 126.2 kB / 35 kB 0.7%↑127.1 kB / 0.7%↑35.2 kB
Total (Includes all files) 126.5 kB / 35.2 kB 0.7%↑127.4 kB / 0.7%↑35.4 kB

🤖 This report was automatically generated by wyvox/pkg-size

// two questions `attachShadow` cannot: is the root still owned by a live block
// (then a second template on the same host stays inert, as the HTML parser
// does), and where is the root of a closed host (`host.shadowRoot` is null).
const SHADOW_BLOCKS = new WeakMap<SimpleElement, RemoteBlock>();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is gross, but closed roots cannot be accessed after they're built otherwise

we also use this to mirror platform behavior where sibling <template> blocks are not allowed (first wins, subsequent inert)

@NullVoxPopuli
NullVoxPopuli marked this pull request as ready for review September 8, 2026 22:52
@johanrd

johanrd commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

weakly held comments:

  1. attachShadow throws NotSupportedError on hosts that can't have a shadow root: <li>, <td>, <a>, <button>, <ul>, SVG elements and others. The guard only checks that the method exists. So <li><template shadowrootmode="open">…</template></li> fails the whole render, where the HTML parser keeps the template inert. Could this check the valid host list, or catch the error and return null?
  2. Any existing host.shadowRoot that is not in SHADOW_BLOCKS gets replaceChildren(), including a custom element's own root or one that an {{#in-element}} fills. The parser reuses only a declarative root with the same mode. Could this do the same, and return null otherwise?

@NullVoxPopuli

Copy link
Copy Markdown
Contributor Author
  1. how would a user be notified that their DOM is incorrect?
  2. the null-fallback? how would a user be notified that their DOM is incorrect?

@johanrd

johanrd commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

true, maybe a debug assert can be useful? not important

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] declarative ShadowDOM is unable to have content rendered in to it [Bug] #in-element cannot directly render in to shadow-dom

3 participants