WICG / webcomponents

Web Components specifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[scoped-registries] What does `new` mean for elements in multiple registries?

keithamus opened this issue · comments

This was originally raised by @matthewp:

class MyElement extends HTMLElement {}
customRegistry.define('my-element', MyElement);
new MyElement();

I can't see how the discussion concluded this point. Are elements allowed on multiple registries? What happens with the following?

class MyElement extends HTMLElement {}
customElements.define('my-element', MyElement);
customRegistry1.define('my-element', MyElement);
customRegistry2.define('my-element', MyElement);
new MyElement();

/cc @xiaochengh @justinfagnani

The same constructor is allowed on multiple registries. However, a direct constructor call will only look up the global registry, because otherwise it has no way to know which registry to use.

See: https://wicg.github.io/webcomponents/proposals/Scoped-Custom-Element-Registries#custom-element-constructors

Yeah, this is spelled out, and was decided on at the Tokyo F2F (I think?).

The main requirement is that new MyElement() has the same behavior with and without the presence of scoped registries - we can't break existing code. So there's only one right answer: it succeeds if the element is registered in the global registry, and fails if it isn't.

I’ll close this out as it has an answer now. Thanks both!