Declarative shadow DOM
A web component keeps its internal markup and styles in a shadow root, and until recently the only way to create one was from JavaScript, by calling attachShadow(). Declarative shadow DOM lets you write the shadow root in the HTML instead. Put a <template shadowrootmode="open"> inside an element, and the browser turns it into that element’s shadow root while it parses the page. A server can send a component fully rendered, and it looks right before any script has loaded.
Delete: the script that finds every <template shadowrootmode> and attaches its shadow root by hand. Keep it only for components that are HTML only, with no JavaScript to render them.
/* the polyfill, on every page */
document.querySelectorAll('template[shadowrootmode]').forEach((t) => {
const mode = t.getAttribute('shadowrootmode');
t.parentNode.attachShadow({ mode }).append(t.content);
t.remove();
});
/* the parser already did this */One more thing to check before deleting. The browser only creates these shadow roots when it parses HTML as the page loads. If your JavaScript builds the same markup later and inserts it with innerHTML, nothing happens: the <template> stays a plain template and no shadow root is created. This is deliberate. The spec disables declarative shadow roots for innerHTML, and the test suite confirms it for every HTML element. So check your code for any innerHTML that inserts markup containing shadowrootmode. For those, either switch to setHTMLUnsafe(), a newer method that does create the shadow roots, or keep the polyfill for that one call.
Every test that matters for this deletion passes in all five current stable runs. The few misses are a newer attribute Safari has not shipped and two document.open() edge cases.
HTML-only components are the one case to keep the polyfill for because they break completely in browsers without this feature. The <template> is ignored and the component’s internal markup never appears.