Recursive AI

Shadow DOM: the model, slots and the flat tree

All onehtml docs

How a shadow root, a slot and the flat tree exist in an immutable snapshot, and how a document with declarative shadow roots is parsed and written. The behaviour here is normative for ports. Spec references: DOM Standard (4.2.2 "Slots", 4.2.14 "attach a shadow root", 4.8 "Interface ShadowRoot"), HTML Standard (13.2.6.4.4 "in head", the template start tag; 13.3 "Serializing HTML fragments"; 4.13.3 "Custom elements" for valid names), CSS Scoping (2.2 "Flattening the DOM").

Scoping selectors (:host, ::slotted(), ::part()) and the scoped cascade, mutation of roots and slot assignment by script, event paths, and the accessibility tree over the flat tree are separate pieces of work and are not described here.

1. The model

  • A shadow root is a node of kind ShadowRoot. It lives in the same node index space as its host, so a node handle or index means the same thing on both sides of the boundary, and anything keyed by node index (boxes, rendered facts, style tables) needs no second key space.
  • Like a template's content root, a shadow root has no parent. Its link to the rest of the tree is its host. The host is the element that holds it, and host.ShadowRoot returns the root in either mode: the library is the user agent, and "open mode only" rules belong to a script runtime.
  • A root's children are the top-level nodes of the shadow tree. They have the root as their parent, so ParentNode walks end at the root, and GetRootNode() of a node in the tree is the root.
  • A root has a mode (Open, Closed), a slot assignment mode (Named, Manual) and the flags DelegatesFocus, Clonable and Serializable. A root made by the parser also reports IsDeclarativeShadowRoot.
  • ContainingShadowRoot is the root of the tree a node is in (the null node for the document tree, a fragment or template content); GetRootNode(composed: true) follows roots to their hosts and ends at the document or the root of a detached tree. IsConnected is true for a node whose shadow-including root is the document, so a node in the root of a connected host is connected.
  • A host has at most one root. Template content and shadow roots are different things: TemplateContent is never a shadow root.

Everything outside the shadow-aware members behaves as before: Children, ChildNodes, Descendants, QuerySelector(All), Closest, TextContent, Contains and CompareDocumentPosition work on one tree and never step across a boundary. doc.Root.QuerySelector("p") does not find a p inside a root; root.QuerySelector("p") searches the root's tree.

Tree scopes and ids

getElementById searches one tree scope: the tree whose root is the document, a fragment or a shadow root. Document.GetElementById searches the document tree only. Node.GetElementById(id) on a shadow root, a fragment or the document searches that scope; on an element it searches the tree the element is in. A label's for resolves in the label's own scope.

2. Parsing declarative shadow roots

ParseOptions.DeclarativeShadowRoots is the parser's "allow declarative shadow roots" flag. It is true by default, as for a document the browser navigates to. Set it to false to parse as innerHTML does; a <template shadowrootmode> is then an ordinary template element. The mutable layer's markup APIs (innerHTML, outerHTML, insertAdjacentHTML) parse with it false, as the DOM Standard says; Document.ParseFragment uses the option as given. An edit re-parses with the flag the document was parsed with.

The steps follow HTML 13.2.6.4.4, "in head", a start tag whose tag name is "template", after the template is pushed:

  1. The declarative shadow host is the current node (not the adjusted current node). In a fragment parse the stack's topmost element is the fragment's own root element, so a top-level template never attaches to the context element: it is an ordinary template.
  2. If the flag is false, the host is the topmost element on the stack, or the template has no shadowrootmode in the open or closed state (ASCII case-insensitive; any other value is the none state), the template is an ordinary template.
  3. Attaching (DOM 4.2.14) can fail. It fails, and the template stays an ordinary template, when the host is not an HTML element, is not one of article aside blockquote body div footer h1 h2 h3 h4 h5 h6 header main nav p section span or a valid custom element name, or already has a shadow root. A second template under a host that has a root is a template element in that host's children. "Already has" is read from the live host when the parser builds into a MutableDocument (a script that ran during the parse may have called attachShadow, in any mode), not only from what the parser itself attached; the same goes for a definition that disables shadow roots and for the depth limit. These checks run before anything is changed, so a host seam never throws out of the parser: the template is simply an ordinary template element (WPT shadow-dom/declarative/declarative-after-attachshadow.html, innerhtml-on-ordinary-template.html).
  4. Otherwise the root is attached with mode, delegatesFocus (the shadowrootdelegatesfocus attribute present), serializable (shadowrootserializable), clonable (shadowrootclonable) and slot assignment (manual when shadowrootslotassignment is manual, else named). shadowrootcustomelementregistry is ignored. shadowrootadoptedstylesheets is kept as given (section 12). The template element is created and pushed on the stack of open elements but never inserted into the tree; its content is the root, so the nodes the parser inserts "inside" the template become the root's children. The template's end tag pops it as usual.

Valid custom element name: starts with a-z, contains -, has no ASCII upper-case letter, only PCENChar characters, and is not annotation-xml, color-profile, font-face, font-face-src, font-face-uri, font-face-format, font-face-name or missing-glyph.

Nesting depth: the template stays on the stack of open elements while its content is parsed, so a hostile chain of hosts and roots counts toward ParseLimits.MaxOpenElements, and each root adds an entry to the list of active formatting elements' markers (MaxActiveFormattingElements). A root is one node (MaxNodes).

Source map

  • The root's own source range is the template's start tag, and its end tag range is the template's end tag, so a root has the extent of the whole <template ...>...</template>.
  • Nodes inside the root keep their own ranges: the bytes between the template's tags. The lossless writer is unchanged (it writes the original bytes), so a document with roots round-trips byte for byte.
  • The source extent of a host without an end tag runs to the furthest end of its last light child chain and of its root.

3. Slots and assignment (DOM 4.2.2)

  • A slot is an HTML slot element. A slot inside a shadow tree takes assigned nodes; a slot elsewhere (the light tree, a fragment, template content) is only an element (IsSlot is true, AssignedNodes() is empty).

  • A slottable is an element or a text node (whitespace text included) that is a child of a shadow host. Comments and processing instructions are not slottable.

  • The slot name of a slot is its name attribute (empty when absent); the slottable name of an element is its slot attribute (empty when absent), and of a text node is empty. Names are compared exactly, so case matters.

  • Named mode. For a root, its slots are the slots among its descendants in tree order, not entering a nested root or template content. A slottable is assigned to the first slot whose name equals its name; later slots with the same name get nothing. A slottable with no matching slot is unassigned.

  • Manual mode. A manual root assigns nothing by itself. Nodes are assigned with MutableNode.Assign on the slot (section 8); the assignments are stored with the working document, a snapshot carries them, and they apply to children of the host only. Assign takes any element or text node, also one of another document (DOM 4.2.2.4 "assign" does not look at the node's document): such a node is remembered and is assigned once it has been adopted into the slot's document and is a child of the host, which is when "find slottables" finds it.

  • A slot assigned into another slot is an ordinary case: the nested slot is a light child of a host inside a shadow tree and is a slottable of that host's root.

  • Assignment is computed when the snapshot is built (when the parse ends with a root in it; for other snapshots, on first use) and never changes. node.AssignedSlot is the slot "find a slot" returns with the open flag unset.

  • slot.AssignedNodes(flatten) and AssignedElements(flatten) follow DOM "find flattened slottables": with flatten, a slot with no assigned nodes uses its children that are slottables, and an assigned node that is itself a slot in a shadow tree is replaced by its own flattened slottables. The walk is iterative and allocates nothing. A non-slot, or a slot not in a shadow tree, gives an empty list.

  • Manual assignment across documents. slot.assign() assignments follow adoption: moving a slot or a listed node to another document and back keeps the link, restored at its old position in the slot's list (docs/dom-node-model.md section 6). While the two are in different documents the node is not slotted. A live query (matches, querySelectorAll) always reads the current manual lists.

4. The flat tree (CSS Scoping 2.2)

The flat tree is the tree rendering and style inheritance use. Shadow roots are not in it; their children stand in for the host's children.

MemberResult
FlatParent of a slotted nodeits assigned slot
FlatParent of a child of a rootthe host
FlatParent of a light child of a host with no assigned slot, or of fallback content of a slot that has assigned nodesnone
FlatParent otherwiseParent
FlatFirstChild, FlatLastChild of a hostthe root's first and last child (the host's light children are not its flat children)
FlatFirstChild, FlatLastChild of a slot in a shadow treeits first and last assigned node; its own first and last child when none are assigned (fallback content)
FlatNext/PreviousSibling of a slotted nodethe neighbour in the slot's assigned list
FlatNext/PreviousSibling of a node that is not in the flat treenone
FlatNext/PreviousSibling otherwiseNextSibling, PreviousSibling
  • A slot stays an element in the flat tree (its user-agent style is display: contents).
  • The root of the flat tree is the document (or fragment). A document with no shadow root has the plain tree as its flat tree, with no cost.
  • FlatChildren and FlatDescendants (preorder, excluding the node) are struct enumerables; they use no stack and allocate nothing, climbing with FlatParent. Every step is O(1).
  • Hosts' unassigned light children (and the host's comment children) have no flat parent. They are still in the tree, in ChildNodes, and in the source.

5. Serialization (HTML 13.3)

Document.SerializeChildren(node, SerializeOptions) and SerializeNode(node, SerializeOptions) implement the HTML fragment serialization algorithm's serializableShadowRoots and shadowRoots arguments. For a shadow host, the root's template is written before the host's children when the root is serializable and SerializableShadowRoots is set, or the root is in ShadowRoots:

<template shadowrootmode="open|closed" then shadowrootdelegatesfocus="" if set, shadowrootserializable="" if set, shadowrootslotassignment="manual" if manual, shadowrootclonable="" if set, shadowrootreferencetarget="..." if the root has one, shadowrootadoptedstylesheets="..." if the root was made with the attribute, then >, the root's children (recursively, with the same options) and </template>.

The overloads without SerializeOptions are unchanged and never write roots (as innerHTML). shadowrootcustomelementregistry is never written. Parse, serialize with every root listed, parse again gives an equal tree.

6. Other consumers

  • Selectors and queries do not cross a boundary (section 1). Matching inside a root treats the root as the top of the tree.
  • Locators. A generated locator is a selector run from the document. A node in a shadow tree has none (TryGenerate returns false); TryGenerateScoped gives its path instead: the locator of the outermost host in the document, the locator of the next host inside that host's root, and so on, ending with the locator of the node inside the innermost root. Each entry is unique in the one tree it is run on (the document, or a single root), and a path of one entry is the plain locator. Inside a root there is no html element to anchor a chain, so a chain that finds no unique attribute anchor starts with a child of the root, written with :not(* *) on its first step, and is accepted only if running it on the root finds exactly the node.
  • Editing. In-memory edits to nodes in a root and to a host's light children are lossless: edits in a root land between the template's tags (prepend and append on the root itself write inside the template); markup inserted into a root is parsed in the host's context; replace, wrap and insert* with markup that has declarative roots attach them (the edit is checked by re-parsing the whole output, so a fragment whose top-level template would attach only in its final position fails the check, not silently); a re-serialized host is written with its root as <template shadowrootmode>. Saved edits for a node in a shadow tree carry a scope path instead of a locator (edit-format.md): replay walks the hosts, then finds the node in the innermost root, or finds it by its source bytes, or goes stale or ambiguous.
  • The mutable layer has its own section, 8.
  • Accessibility and validation read the flat tree: docs/accessibility-tree.md ("Shadow roots") and docs/checker.md ("Shadow roots"). A shadow root node itself never appears in the accessibility tree.

7. Decisions the specs leave open

  • A root's properties and host link live in the node's own columns; no behaviour depends on the layout.
  • AssignedSlot and the flat tree are not restricted by mode: closed roots are navigable.
  • A template that becomes a root's content is not in the tree at all (not a child of the host), so host.Children never shows it; the spec's template element exists only on the parser's stack.
  • IsConnected is the shadow-including notion.
  • Slot assignment treats every text node, including whitespace, as slottable, as the DOM Standard does.

8. The mutable layer (RecursiveAI.OneHtml.Mutation)

Shadow roots are nodes of the working document like any other (NodeKind.ShadowRoot), with handles that survive commits. Everything here is guarded by "does the document have any root": a document without roots does no slot work and allocates nothing extra per edit.

Attaching. MutableNode.AttachShadow(ShadowRootInit) follows DOM 4.9 "attach a shadow root" and HTML 4.13.2 "valid shadow host name":

  • The host must be an HTML-namespace element whose local name is one of article aside blockquote body div footer h1–h6 header main nav p section span or a valid custom element name (a name with a hyphen that is not one of the reserved names). Anything else is NotSupportedError, as is a host that already has a root.
  • The exception to "already has a root": a root the parser made from a declarative template. If its mode equals the requested one, AttachShadow empties it, keeps its mode, delegatesFocus, clonable, serializable and slot assignment, clears its declarative flag and returns it; a second call then throws. A different mode throws.
  • ShadowRootInit.Of(root) reads a root's settings as an initializer (the WebIDL dictionary conversion that lets a ShadowRoot stand for the dictionary).
  • MutableDocument.CustomElementDisablesShadow is a callback seam: a custom element whose definition disables shadow gets NotSupportedError, and the parser leaves its declarative template in place. Nothing sets it until a registry exists.
  • Depth: a root counts toward MaxDepth as one more level under its host, so nesting hosts and roots cannot get past the limit; the check is made before the root is created.

Live slot assignment. Insertion, removal, slot and name attribute changes, and moving slots or hosts' children update assignment immediately, per DOM 4.2.2 "assign slottables for a tree": AssignedSlot, GetAssignedSlot(openOnly), GetAssignedNodes(flatten) and GetAssignedElements(flatten) are always current, and a snapshot taken from the working document computes the same assignment (a test compares them over random edit sequences). GetAssignedSlot(openOnly: true) is what script sees (a closed root's slot is hidden); the plain AssignedSlot is the user agent's.

  • Assign (manual mode). slot.Assign(nodes) stores the list for the slot (elements and text nodes only; anything else is an ArgumentException, where script gets a TypeError), moves a node out of the slot that held it, ignores repeats (first wins), and runs assignment again for the slot's tree and for the tree of every slot that lost a node. A node takes effect only while it is a child of the root's host and the slot is in that root; otherwise it is remembered and takes effect when that becomes true. Moving a slot to another root, or removing it, drops what it had; a node moved under another host loses its slot.
  • Departure from the literal DOM text, with the evidence. DOM 4.2.1 "insert" runs "assign a slot" for a new child only when the parent's shadow root is in named mode, so by the letter a node inserted under a manual host stays unassigned even if an earlier assign named it. Browsers and the web-platform test shadow-dom/imperative-slot-api.html ("Assigning invalid nodes should be allowed", "Appending slottable to different host, it loses slot assignment...", "Previously assigned node should not be assigned if slot moved to a new shadow root. The node is re-assigned when moved back") expect the remembered assignment to take effect when the node returns under the host, so manual hosts also reassign on insertion. Slots_html-style named behaviour is unchanged.
  • Signals. Whenever a slot's assigned nodes change, or a slot with no assigned nodes has its fallback content changed, the slot is added to the document's signal list, as DOM 4.2.2 "signal a slot change" says (de-duplicated, in the order first signalled). MutableDocument.PendingSlotChanges and TakeSlotChanges() read and drain it. NotifyMutationObservers() takes the list after it delivers observer records, at steps 3, 4 and 6 of DOM 4.3.1 "notify mutation observers", calls MutationHooks.SlotChangeSteps(slot) for each slot, and queues the microtask through the existing microtask request. Firing the slotchange event itself is the events work's.
  • Change sets. DocumentChanges.FlatChildrenChanged lists nodes whose flat-tree children may have changed (hosts, slots and nodes whose parent is a slot, and the parents of inserted and removed nodes in a rooted tree; a superset of the nodes whose flat children really differ), SlotsChanged lists slots whose assigned nodes changed, and ShadowRootsAttached lists hosts that got a root since the last commit. All three are merged by ChangesSince.

Clone, import, serialize. CloneNode of a host copies its root only when the root is clonable, and always deep (a shallow clone of a host still deep-clones the root, DOM 4.5 "clone a node"); Import follows importNode and clones only clonable roots. Cloning or importing a shadow root itself is NotSupportedError. A root is a document-fragment kind: inserting one into a parent inserts its children and leaves it empty, as for a fragment (DOM 4.8; shadow-dom/Range-prototype-insertNode.html). GetHtml(serializableShadowRoots, shadowRoots) is HTML 13.3 getHTML; innerHTML and outerHTML never write roots. SetHtmlUnsafe and the ParseFragment(html, context, declarativeShadowRoots) overload parse with the declarative flag; SetInnerHtml does not (HTML 13.2.2).

9. Reference targets

A shadow root can name an element of its own tree that stands for the host when something refers to the host by id (the explainer is WICG/aom reference-target-explainer.md; the WPT files are shadow-dom/reference-target/tentative/). Chrome 156 ships it. It is not in the HTML Standard yet, so everything here is a decision of this library.

  • The value. Node.ReferenceTarget on a root: null when there is none, the empty string when the attribute was present and empty, else the id as written (case-sensitive). The declarative attribute is shadowrootreferencetarget on the template (its name is case-insensitive like any attribute); the mutable layer takes it from ShadowRootInit.ReferenceTarget and changes it with MutableNode.ReferenceTarget (or SetReferenceTarget, which can follow a call chain). Changing it makes the document dirty, so the next commit has a new snapshot; the commit lists no node as changed, and a consumer that reads references (the accessibility tree and the checker) rebuilds when a document uses reference targets. A clone of a clonable root, an imported root and an edit that inserts markup with the attribute keep it.
  • Serialization. shadowrootreferencetarget="..." follows shadowrootclonable and is written whenever the value is not null, empty included (so the order is mode, delegatesfocus, serializable, slotassignment, clonable, referencetarget). The value is escaped as an attribute value.
  • Resolution. Node.ResolveReferenceTarget() on an element: a host whose root has a target stands for the element of that root with that id (the first in the root's tree order), and so on through nested hosts; an element that is not a host, or whose root has no target, stands for itself; the empty string, an id that no element of the root has, or a link that fails anywhere in the chain gives the null node (the reference is unresolved, it does not fall back to the host). Node.GetReferencedElement(id) is the lookup for an ID reference held by a node: the first element with the id in the node's tree scope (as GetElementById), then the resolution. The DOM-level reflection of an id attribute is the host (GetElementById), as for ariaLabelledByElements or label.control's attribute in the script bindings; the resolution is what the accessibility name, the label association and the form association use.
  • Attributes covered. aria-labelledby, aria-describedby, aria-controls, aria-details, aria-errormessage, aria-flowto, aria-activedescendant (names and relations in the accessibility tree), for on a label, form on a form-associated element, list on an input, and the invoker attributes commandfor, popovertarget and interestfor (resolution only: the toggling and the command events belong to the host that runs them). aria-owns is not followed: its behaviour is undecided in the specifications (WICG/webcomponents 1091, w3c/aria 2266), so an owner takes the host.
  • Labels. Node.Control of a label with a for is the resolved element when it is labelable. A label without for has as its control the first descendant in tree order (the label's own tree; shadow trees are not entered) that is labelable, or that is a host with a reference target that resolves to a labelable element, which is then the control; a host whose target resolves to something else, or that has none, is skipped. Node.Labels of a labelable element lists the labels whose control it is, in shadow-including tree order, looking in its own tree scope and in the scopes of the hosts above it (a label outside the root can label a control inside). The labelable elements are the HTML ones: button, input that is not hidden, meter, output, progress, select, textarea.
  • Form owner. Node.FormOwner of a form-associated element: the form its form attribute names in its own tree scope, with a host standing for the form its target resolves to, else the nearest form ancestor. A control in a different tree scope than the form's host does not reach it by id.
  • Not modelled. The script reflections (ShadowRoot.referenceTarget as a property with string coercion, HTMLTemplateElement.shadowRootReferenceTarget, the element-reflecting properties and their invalid-target behaviour), form.elements live collections, the reset and click activation of the form.html tests, and the events of event-path.html (CommandEvent, ToggleEvent, SubmitEvent and InterestEvent with a source, retargeted so that only the shadow trees between target and source see them).

10. Focus on hosts and targets after dispatch

  • :focus on a shadow host (Selectors 4; HTML 6.6.3 "focus chain"). A host matches :focus (and :focus-visible, when the focus is visible) while an element of its shadow tree, at any depth of nested shadow trees, is focused, whether or not the root delegates focus. The host is reached only by crossing a shadow root: an element assigned to a slot is a DOM child of the host, and focusing it does not focus the host. :focus-within already followed the flat tree. Restyle: a plain :focus rule on a host is an anchor for focus changes inside its tree, and a document with shadow trees skips the focus-reach shortcut of DocumentStyles.WithContext and takes the full scan.
  • Targets after dispatch (DOM 2.9 "clearTargets"). It is decided from the last path item that has a shadow-adjusted target, which is the target as the outermost listener saw it: true when that target or related target, or any touch target, has a shadow root as its root. Then Target, RelatedTarget and every touch target are null after dispatch. A composed event that leaves the shadow tree ends as the host and clears nothing. WPT: event-post-dispatch*.html, event-post-dispatch-listenerless.html.
  • Trusted slotchange. The event the library fires at a signalled slot is trusted; see events.md.
  • Template contents and host-including ancestors. html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy.html is translated for its first and third tests (ConformanceAskTests.Template_content_refuses_its_host_and_the_hosts_ancestors, Template_content_refuses_an_ancestor_across_two_template_boundaries). The second test moves a template's contents to another document with adoptNode first; it is not translated, because adopting a template's contents fragment on its own is not a supported operation (the hierarchy check it then repeats is the same walk).

11. Chrome parity on component pages

The claim: pages built from real component libraries style and expose the same as in Chrome. The harness is tools/components (see its README); the comparisons are OneHtml.Differential components (computed styles) and ax (accessibility tree).

Method. Chrome for Testing 156.0.8078.47 (protocol 1.3), headless, 1280x800, on a 32-core Linux worker; the pages are served from a loopback port with scripts running. Components: Lit 3.3.3 (sample elements of our own using its API: adopted style sheets, slots, ::slotted, parts, delegatesFocus, ElementInternals), Shoelace 2.20.1 (about 45 components: button, button group, input, textarea, checkbox, switch, radio and radio button, select, range, rating, tab group, card, alert, badge, tag, details, progress bar and ring, spinner, avatar, breadcrumb, dropdown and menu, tooltip, icon button, tree, divider, skeleton, dialog) and Material Web 2.5.0 (about 30: the five button kinds, icon buttons, fab, checkbox, radio, switch, filled and outlined text fields, selects, slider, chips, progress, tabs, list, divider, menu, dialog). One page of plain light-DOM markup of the same element types is the control. After the components have rendered, the harness takes Chrome's tree and CSS.getComputedStyleForNode for every element of the flat tree, then writes the page as declarative shadow roots (adopted sheets as <style data-adopted>, form state and ElementInternals roles as attributes) and the library reads that markup. Elements are paired through the DOMSnapshot adapter.

Styles. Over the 1,662 elements of the Lit, Shoelace and Material Web pages, 121,326 values of the properties the capture lists (layout-resolved ones such as width left out) were compared. 5,107 (4.2%) differ as text (27,268, 22.5%, before the form-control user-agent style and the computed forms below were added). Most of those are the same value in other words (a colour keyword and rgb(), currentcolor and the resolved colour, a unitless line-height and the used length, inline and block for a flex item, font-family quoting, a shadow list in Chrome's order, user-select: auto and its used value); a value-form normalization (documented in the command's README) removes them. After it 23 values (0.019%) differ on the three libraries' pages and one more on the modal-dialog pages, against 2,108 (1.74%) before. The control page, plain light-DOM markup of the same elements, differs by 21 of 6,716 values (0.31%, from 5.99%), and 17 of the library values are the same differences in the same form (text-align, overflow), so they are not Shadow DOM findings. The seven that are not shared with the control page:

propertyvaluescause
border-*-color4one text field's border, rgba(118, 118, 118, 0.3) in Chrome and the enabled colour in ours (not isolated; the control page's field agrees)
clip-path1Chrome writes six significant digits in a polygon(), ours keeps the exact lengths
box-shadow1a running animation (Chrome reports the current frame)
position1a modal dialog in the top layer is fixed in Chrome; the top layer is script state

What the unit changed to get there: env() is substituted per CSS Environment Variables 1 (docs/cascade.md, "env()"); the user-agent sheet gives form controls Chrome's platform font, borders, padding, backgrounds, cursors and disabled colours (docs/cascade.md, "Form-control defaults"); an SVG element other than the outermost svg is position: static; nested calc() and min() are simplified and a unitless zero length computes to 0px; border and outline widths snap as Chrome does; border-*-color and the other colour properties resolve currentcolor and the deprecated system colours on rendered elements.

The comparison has a negative control: OneHtml.Differential components --negative-control replaces every 50th Chrome value by one that cannot be equal and exits non-zero unless every replaced value is reported (2,710 of 2,710 on these captures).

Custom properties: 366,135 values over 1,043 names, none differ, across slots, :host rules and inheritance into every root.

Accessibility tree (with rendered facts). Per field, over 1,347 nodes of the same eight captures: role 0% (792 compared), name 0.88% (7; 9 of 623 before), nameSource 0.29% (1), description 0%, hidden 0.07% (1), ignored 2.5% (34), exposedParent 4.5% (60), chromeOnly 1.7% (14), oursOnly 1.7% (14), checked 7% (2 of 28), disabled 31% (4 of 13). The harness found two differences of ours that are fixed (entries slot-with-box, name-descendant-roles, name-hidden-slot-text and name-labelledby-root-content of the Chromium profile): a slot an author style gives a box was always ignored, and a name from contents read the wrong descendants and the wrong slotted text.

Open, all from state markup cannot carry or Chrome behaviour with no specification text:

  • Click handlers (a dozen of the ignored nodes): Chrome keeps a generic element that has a click listener (md-icon-button, md-switch, md-slider, sl-icon-button); listeners are not in the markup.
  • References set from script (relations): ariaLabelledByElements and the like point across roots; only attributes are in the markup.
  • Focus and form state (focused, part of checked and disabled): focus is not in markup; a few control states are set by script after the write-back.
  • Hosts and wrappers Chrome leaves out (md-list-item, md-menu-item with no box, the host of a closed sl-popup): Chrome ignores them as uninteresting where our layout rule exposes them.
  • Names (7): six are form-associated custom elements (md-checkbox, md-radio, md-switch) whose role and label come from a class's static formAssociated and ElementInternals, which markup does not carry, so they need a script host; one is the Choose File button of input type=file on the control page, whose text comes from a user-agent shadow tree we do not model.

Not shipped by Chrome 156: shadowrootadoptedstylesheets (probe: no shadowRootAdoptedStyleSheets property on HTMLTemplateElement, and a template with the attribute adopts no sheet), it is implemented all the same (section 12), and its tentative tests count.

12. Declarative adopted style sheets (shadowrootadoptedstylesheets)

A template with shadowrootmode can name style sheets its root adopts: <template shadowrootmode=open shadowrootadoptedstylesheets="foo bar"> (the proposal is whatwg/html pull request 12339; the web-platform-tests files are shadow-dom/declarative/tentative/shadowrootadoptedstylesheets/). Chrome 156 does not ship it, and the HTML Standard does not have it yet, so the behaviour below follows the tentative tests and is additive: a page that never uses the attribute sees no change.

  • What the library holds. Node.AdoptedStyleSheetSpecifiers (and MutableNode.AdoptedStyleSheetSpecifiers) on a root is the raw attribute value: null when the attribute was absent, the empty string when present and empty, otherwise the text exactly as authored, whitespace included. Serialization (getHTML with serializable roots, and the editor's markup writer) writes it back as given, after shadowrootreferencetarget, and omits it when absent. ShadowRoot.getHTML() writes no template, so no attribute. Sheets that script adds to adoptedStyleSheets have no specifier and are never serialized, and they do not change the attribute value.
  • The library never fetches. Specifier resolution (import maps, URLs, the module map of fetched CSS modules) belongs to the host that runs scripts and loads resources. The host sets MutableDocument.AdoptedSheetSpecifierResolver (or MutableDocumentOptions.AdoptedSheetSpecifierResolver, which supplies the initial value so that roots a document is made with resolve too). With no resolver, which is how a document with no module map behaves (Document.parseHTMLUnsafe, the same-document test), a root adopts nothing, but keeps the attribute.
  • Resolution steps (when a root with the attribute is made by the parser, by SetHtmlUnsafe or fragment parsing, or by a clone or import of a clonable host; each resolves again in the document that receives the copy, never from the source's maps): split the value at ASCII whitespace into an ordered set, so repeated tokens are dropped and a bare name and its resolved URL are different tokens; ask the resolver for each token, in order. AdoptedSheetResolution.Unresolvable adds nothing; Ready(sheet) adds that sheet object, so every root that names it shares one instance; Pending(key) adds an empty stand-in sheet (ConstructedStyleSheet.PendingKey is the key, normally the resolved URL). The result becomes the root's AdoptedStyleSheets. An empty or all-whitespace value gives an empty list.
  • Completion. When the sheet arrives, MutableDocument.CompleteAdoptedSheet(key, sheet) replaces every adopted stand-in with that key, in every document node and shadow root of the document, including roots whose host is detached (the replacement is waiting when the host is inserted again). A stand-in script removed from the list is not put back, and one that script put back, or moved to another position or root, is replaced where it now is. A stand-in that script changed (ReplaceSync, WithMedia, WithDisabled) keeps its key and is replaced too, and its changes are lost, as in the tests (mutation-insertrule, mutation-replacesync). A failed load calls nothing: the stand-in stays and stays empty. The replacement is reported in the next commit's DocumentChanges.AdoptedStyleSheetsChanged, so styles restyle as for any adopted-sheet change.
  • Stand-in identity. The fetched sheet is a different object from the stand-in (placeholder-identity); the stand-in stays empty. Two entries naming one URL (a bare name and its URL) are replaced by the same sheet object.
  • Clone and import. A clone of a clonable host copies the attribute value and resolves it again; the clone shares the sheet of a resolved specifier and gets its own stand-in for a pending one. Scripted changes to adoptedStyleSheets are not copied. Import into another MutableDocument resolves against that document's resolver, so a specifier that only the source document maps adopts nothing.
  • Script bindings. The IDL attribute HTMLTemplateElement.shadowRootAdoptedStyleSheets reflects the content attribute and is the binding's, as is the module map and import() of CSS modules; the library offers the resolver seam and the completion call those use.