justinribeiro / lite-youtube

The fastest little YouTube web component on this side of the internet. The shadow dom web component version of Paul's lite-youtube-embed.
https://www.npmjs.com/package/@justinribeiro/lite-youtube
MIT License
836 stars 63 forks source link

Update lite-youtube.ts #84

Open amoreaulemay opened 1 year ago

amoreaulemay commented 1 year ago

Guards customElements from redefining 'lite-youtube' if it already exists.

justinribeiro commented 1 year ago

Humm, the double-stamp workaround. This seems to me (now, in 2023) unnecessary unless you're working with a build that is not properly de-duplicating the module. Is there a specific case you're trying to work around?

amoreaulemay commented 1 year ago

Yes, we use a component library that bundles every component as its own module. We have a few variants of these components on one page but because they are self contained they redeclare the component.

As a general rule, it's also a good guard to check if the component is already defined.

justinribeiro commented 1 year ago

Yes, we use a component library that bundles every component as its own module. We have a few variants of these components on one page but because they are self contained they redeclare the component.

Sigh, that is not great pattern for so many reasons.

As a general rule, it's also a good guard to check if the component is already defined.

Nahhh, it's a workaround for bad build behaviors and poor dependency management. We never had a rule in the wc gold standard for it, it's always been considered a dirty fix, and you don't find it in most of the heavy-use web components. Case in point: https://github.com/google/model-viewer/blob/1811263f6cf0bb7b1ab64f67d3002101eafd997d/packages/model-viewer/src/model-viewer.ts#L39

Let me give it some though before I cut a point release this week.