Skip to content

Prevent attempted double registration of the web-component #202

@davidsneighbour

Description

@davidsneighbour

customElements.define('lite-youtube', LiteYTEmbed);

Adding the script more than once results in browser console errors

youtube/:7699 Uncaught NotSupportedError: Failed to execute 'define' on 'CustomElementRegistry': the name "lite-youtube" has already been used with this registry

The component JS always runs customElements.define() instead of checking, if the component is already defined, using for instance.

if (!customElements.get('lite-youtube')) {
  customElements.define('lite-youtube', LiteYTEmbed);
} else {
  // do nothing or print a nice warning
}

While it is better to instantiate this right away correctly, people might attempt to add the script twice per site or even once per embed if used multiple times per page. Checking if it's already defined would silence the browser console.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions