Skip to content

Conversation

@tronicboy1
Copy link

Reference Issue

Fixes #3794

Change customElement decorator to not define a custom element if it is already in the registry.

This eliminates DOM exceptions when multiple scripts are accidentally imported.

@google-cla
Copy link

google-cla bot commented Apr 7, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@justinfagnani
Copy link
Contributor

Even though this is a small code change, it is a major behavior change that would require an RFC. @customElement() is only a declarative shorthand for customElements.define() - it's been important that the behavior matches. We also don't put features in decorators that are not available in plain JS.

Given a single global registry, and no way to tell if two registrations for the same name are compatible, throwing is the more correct and conservative thing to do. We may wish to explore some other option, but that would involve some way of element definition describing what other definitions they are compatible with and still throwing if they aren't known to be compatible.

@tronicboy1
Copy link
Author

@justinfagnani
I totally understand where your coming from with that. You could have multiple packages trying to define the same name and have no way to see that as an error.

I'll close this PR, sorry for wasting your time!

@tronicboy1 tronicboy1 closed this Apr 10, 2023
@tronicboy1 tronicboy1 deleted the #3794/custom-element-definition-check branch April 10, 2023 00:24
@justinfagnani
Copy link
Contributor

@tronicboy1 not a waste. I think we should do something here for use cases that need it, it's just a little complicated. Hopefully scoped element registries solve most cases.

@tronicboy1
Copy link
Author

@justinfagnani
First time hearing about scoped registries. Your proposal makes a lot of sense and I for one would be very happy to see it realized!

thanks again for all of your work.

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

Successfully merging this pull request may close these issues.

customElement decorator causes DOM exception when accidentally executed twice

2 participants