Skip to content

Behavior of innerHTML on element with scoped custom element registry #11382

Open
@sorvell

Description

@sorvell

What is the issue with the HTML Standard?

Elements created via element.innerHTML on an element with a scoped registry do not gain the registry; however, elements created via shadowRoot.innerHTML on a shadowRoot with a scoped registry do.

The intent in #10854 is that Element should support an associated CustomElementRegistry, exposed through a customElementRegistry getter. This impacts elements created through innerHTML and future such methods, such as setHTMLUnsafe(). The current behavior in Safari Technical Preview 221 (example) does not appear to follow this intent. This issue is intended to resolve any spec related concerns.

// element.innerHTML
const customElementRegistry = new CustomElementRegistry();
const div = document.createElement('div', {customElementRegistry});
console.assert(div.customElementRegistry === customElementRegistry, 'via createElement');
div.innerHTML = `<div></div>`;
const child = div.firstChild;
// Fails
console.assert(child.customElementRegistry === customElementRegistry, via element.innerHTML');    

// shadowRoot.innerHTML
const host = document.createElement('div');
const shadowRoot = host.attachShadow({mode: 'open', customElementRegistry});
console.assert(shadowRoot.customElementRegistry === customElementRegistry, 'via attachShadow');
shadowRoot.innerHTML = `<div></div>`;
const shadowChild = shadowRoot.firstChild;
// Passes
console.assert(shadowChild.customElementRegistry === customElementRegistry, via shadowRoot.innerHTML');

Metadata

Metadata

Assignees

Labels

topic: custom elementsRelates to custom elements (as defined in DOM and HTML)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions