What is the issue with the HTML Standard?
As currently spec-ed customElementRegistry.initialize(element) both sets element.customElementRegistry but also recurses all descendents and also sets customElementRegistry on those descendents.
This is particularly limiting when combined with #12000 as it means non-cooperating scripts (or even just async scripts) can't effectively call .initialize on relevant elements without potentially affecting children which should be initialized with a different registry.
I'd like to propose that .initialize has an option to avoid recursing past an element with an existing custom element registry (and as part of #12000, a sub element customelementregistry="" sets a flag to prevent recursive initialization).
To demonstrate this with an example, suppose we had the following HTML (with #12000):
<some-third-party-element customelementregistry="">
<custom-element></custom-element>
<some-first-party-element customelementregistry="">
<custom-element></custom-element>
</some-first-party-element>
</some-third-party-element>
I propose that in the following code:
const registry = new CustomElementRegistry();
registry.define("custom-element-1", class extends HTMLElement{});
registry.initialize(
document.querySelector("some-third-party-element"),
{ scoped: true },
);
only the first <custom-element> would be upgraded as a result of this call to initialize. (<some-first-party-element> can then upgrade it's children as it pleases).
What is the issue with the HTML Standard?
As currently spec-ed
customElementRegistry.initialize(element)both setselement.customElementRegistrybut also recurses all descendents and also setscustomElementRegistryon those descendents.This is particularly limiting when combined with #12000 as it means non-cooperating scripts (or even just
asyncscripts) can't effectively call.initializeon relevant elements without potentially affecting children which should be initialized with a different registry.I'd like to propose that
.initializehas an option to avoid recursing past an element with an existing custom element registry (and as part of #12000, a sub elementcustomelementregistry=""sets a flag to prevent recursive initialization).To demonstrate this with an example, suppose we had the following HTML (with #12000):
I propose that in the following code:
only the first
<custom-element>would be upgraded as a result of this call toinitialize. (<some-first-party-element>can then upgrade it's children as it pleases).