Skip to content

Custom element registry handling on insert after adopt #1412

@ja-y-son

Description

@ja-y-son

What is the issue with the DOM Standard?

While going through the WPT in adoption.window.js, there are some tests I'm having a hard time reasoning through with the logic outlined in spec. Specifically, I want to clarify the behavior of null registry handling on insert when a cross-document adoption happens.

Take "Adoption with explicit global registyr into a scoped registry (scoped registry target)" test case for example,

test(t => {
  const documentRegistry = new CustomElementRegistry();
  const contentDocument = document.implementation.createHTMLDocument();
  documentRegistry.initialize(contentDocument);
  assert_equals(contentDocument.customElementRegistry, documentRegistry);

  const element = document.createElement('div', { customElementRegistry: customElements });
  assert_equals(element.customElementRegistry, customElements);

  const scoped = new CustomElementRegistry();
  const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped });
  contentDocument.body.appendChild(scopedElement);
  assert_equals(scopedElement.customElementRegistry, scoped);
  scopedElement.appendChild(element);
  assert_equals(element.customElementRegistry, null);
}, "Adoption with explicit global registry into a scoped registry (scoped registry target)");

My understanding of the goal in this test is that when element is appended in scopedElement, which is a cross document adoption, according to the adoption spec, in step 3-1-3-2, "If inclusiveDescendant’s custom element registry is a global custom element registry, then set inclusiveDescendant’s custom element registry to document’s effective global custom element registry.", which results in null in element.customElementRegistry.

However, given that appendChild/append also run insert steps, according to insert step spec, after the adoption happens in step 7-1, in step 7-7-3-1, "If inclusiveDescendant’s custom element registry is null, then set inclusiveDescendant’s custom element registry to the result of looking up a custom element registry given inclusiveDescendant’s parent.", wouldn't this step assign a registry (in this case scopedElement's registry) to element?

Not sure if I missed anything in my reasoning above, would like to get some clarification on the spec around this logic.

cc @annevk @rniwa

Metadata

Metadata

Assignees

No one assigned

    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