[whatwg/dom] custom element registry mutability in an element (Issue #1414)

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

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

I remember we wanted to make sure custom element registry can only be set once, but I'm seeing some inconsistency in WPT and in Safari

Consider this code snippet tested in Safari 228
```
const registry = new CustomElementRegistry;

const element = document.createElement('new-element');
document.body.appendChild(element);
element.customElementRegistry === window.customElements   // true

const shadow = document.createElement('div').attachShadow({mode: 'open', customElementRegistry: registry})
shadow.appendChild(element)
element.customElementRegistry === registry   // true

document.body.appendChild(element)
element.customElementRegistry === window.customElements   // false
```

In above scenario, `element`'s custom element registry changed when it's moved into a shadow root, but remained unchanged when it's moved out of the shadow root.

Similarly, in this [WPT](https://github.com/web-platform-tests/wpt/blob/5dabda7dba04551427592363dcb79d6db7c90e37/custom-elements/registries/scoped-registry-define-upgrade-criteria.html#L147), 
```
test(t => {
  const name = nextCustomElementName();

  const registry = new CustomElementRegistry;
  const shadow1 = attachShadowForTest(t, registry);
  const node = shadow1.appendChild(document.createElement(name));

  const shadow2 = attachShadowForTest(t, new CustomElementRegistry);
  shadow2.appendChild(node);

  class TestElement extends HTMLElement {};
  registry.define(name, TestElement);

  assert_false(node instanceof TestElement);
}, 'Adding definition to scoped registry should not upgrade nodes no longer using the registry');
```
seems to be expecting the node's registry to be changed after moving from shadow1 to shadow2 so it doesn't get upgraded.

I don't think we have a clear guide in the spec on how and when an element's custom element registry can be changed. From the first example, it seems like it's okay for global registry to be mutated, but in the second example, it seems like the scoped registry also got the same expectation of being mutable.


cc @annevk @rniwa 


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

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

Received on Thursday, 9 October 2025 21:46:38 UTC