Description
Describe the problem
At ADEO group, we are working in a Web-component and we are using Svelte to build our web component.
Using the config customElement: true
we are able to create web component from our Svelte component.
When using the svelte:options tag, we have a web component with the name defined in the tag.
<svelte:options tag="my-component" />
Everything works fine so far,
Our library is used with a micro front architecture.
Many apps can call the same web component.
And we have this error:
Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "my-component" has already been used with this registry
Describe the proposed solution
A solution that we have on our end is to check if the custom element has been registered.
If not, then we register it.
In this file src/compile/render-dom/index.ts
: https://github.com/sveltejs/svelte/blob/master/src/compiler/compile/render_dom/index.ts#L572
You could add:
if (!@_customElements.get("${component.tag}")) {
@_customElements.define("${component.tag}", ${name});
}
Let me know if you want me to contribute.
Alternatives considered
The alternative we found, is to declare the tag
as null
.
And create a file with the check for each web component library.
Importance
would make my life easier