Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
keithamus opened this issue Apr 21, 2023 · 3 comments
Closed

Comments

@keithamus
Copy link
Collaborator

keithamus commented Apr 21, 2023

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

@xiaochengh
Copy link

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

@justinfagnani
Copy link
Contributor

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.

@keithamus
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants