Skip to content

Instantly share code, notes, and snippets.

@jonmann20
Created February 19, 2018 14:49
Show Gist options
  • Save jonmann20/aedae15cbf78c820c8c28e83f39f797c to your computer and use it in GitHub Desktop.
Save jonmann20/aedae15cbf78c820c8c28e83f39f797c to your computer and use it in GitHub Desktop.
Dedup custom elements
let _define = customElements.define;
let registered = [];
customElements.define = function() {
const componentName = arguments[0];
if(registered.includes(componentName)) {
console.error(`Trying to register ${componentName} more than once`);
return;
}
registered.push(componentName);
return _define.apply(this, arguments);
};
@jonmann20
Copy link
Author

Use this to fix duplicate component errors:

(index):18 Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry
    at CustomElementRegistry.customElements.define

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment