Skip to content

Stopping recursion in customElementRegistry.initialize across different custom element registries #12035

Description

@Jamesernator

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interesttopic: custom elementsRelates to custom elements (as defined in DOM and HTML)

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions