lit / lit-element

LEGACY REPO. This repository is for maintenance of the legacy LitElement library. The LitElement base class is now part of the Lit library, which is developed in the lit monorepo.
https://lit-element.polymer-project.org
BSD 3-Clause "New" or "Revised" License
4.49k stars 318 forks source link

Do not redefine class in `customElement` decorator if already defined #1246

Closed tronicboy1 closed 1 year ago

tronicboy1 commented 1 year ago

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[bot] commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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!

justinfagnani commented 1 year ago

@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 commented 1 year ago

@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.