[whatwg/dom] Custom element registry handling on insert after adopt (Issue #1412)

ja-y-son created an issue (whatwg/dom#1412)

### What is the issue with the DOM Standard?

While going through the WPT in [adoption.window.js](https://github.com/web-platform-tests/wpt/blob/master/custom-elements/registries/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](https://github.com/web-platform-tests/wpt/blob/8f85e55bbbb5e8288bff242fa7a960113400c3c0/custom-elements/registries/adoption.window.js#L380) 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](https://dom.spec.whatwg.org/#concept-node-adopt), 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](https://dom.spec.whatwg.org/#concept-node-insert), 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 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1412
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1412@github.com>

Received on Wednesday, 8 October 2025 18:15:58 UTC