-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a check before defining the component in the registry #7595
Comments
I don't think this is Svelte job.
Yes. I think this is proper way. |
Thanks for your reply @baseballyama |
I think this should be reopened (or maybe a new issue created). I'm tinkering with this in version 4 and it looks like this simple API might to come up as a problem again in version 4. So, this doesn't look like it'll work anymore: customElements.define("custom-element", CustomElement); Due to the changes merged in #8457, the So, if you want to use HMR with Vite and custom elements (e.g. noted in #6164 and probably others), you would need to duplicate the options in your import { create_custom_element } from "svelte/internal";
if (!customElements.get("custom-element")) {
customElements.define("custom-element",
create_custom_element(
CustomElement, // the component constructor
{"camelCase1":{"reflect":true,"type":"String","attribute":"camel-case1"}}, // props_definition
["default"], // slots
[], // accesors
false // Shadow dom
)
);
} This naturally doesn't feel like the right ultimate solution for v4 (with Vite, the default dev server) since obviously you probably shouldn't be importing from Edit: Created #8681 to address the above. |
I think it's good to open a new issue! |
Alright @baseballyama, created #8681 to address that separate issue instead (i.e. in v4 with the constructor no longer being descendant of For what it's worth, I ended up here since I had the same error as @mohamedMok (since I wasn't using |
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:
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#L572You could add:
Let me know if you want me to contribute.
Alternatives considered
The alternative we found, is to declare the
tag
asnull
.And create a file with the check for each web component library.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: