-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
cannot export functions from custom elements in dev #8971
Comments
I can't reproduce this in the REPL. Are you using hot module reloading by any chance? That's known to cause issues with custom elements. |
I don't think it's related to HMR, this happens on a fresh page load. I think it's difficult to accurately reproduce in the repl, because App.svelte is rendered for you, so you can't actually use the component as a custom element via its tagname. But if you look at the generated code, you will see
that then fails here, becuse "increment" is being defined twice: svelte/packages/svelte/src/runtime/internal/Component.js Lines 417 to 423 in f41ff96
|
Compare the code output in dev mode: class App extends SvelteComponentDev {
constructor(options) {
super(options);
init(this, options, instance, create_fragment, safe_not_equal, { increment: 0 });
dispatch_dev("SvelteRegisterComponent", {
component: this,
tagName: "App",
options,
id: create_fragment.name
});
}
get increment() {
return this.$$.ctx[0];
}
set increment(value) {
throw new Error("<my-counter>: Cannot set read-only property 'increment'");
}
}
customElements.define("my-counter", create_custom_element(App, {}, [], ["increment","increment"], true)); to non-dev mode: class App extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment, safe_not_equal, { increment: 0 });
}
get increment() {
return this.$$.ctx[0];
}
}
customElements.define("my-counter", create_custom_element(App, {}, [], ["increment"], true)); |
Ah I see, thanks for the clarification! |
In dev mode, Svelte creates a setter to throw an error noting that you can't set that readonly prop, which resulted in the accessor getting applied twice to the custom element wrapper, causing an error fixes #8971
In dev mode, Svelte creates a setter to throw an error noting that you can't set that readonly prop, which resulted in the accessor getting applied twice to the custom element wrapper, causing an error fixes #8971
Describe the bug
in dev, if you export a function from a svelte component that is a custom element, you receive an error in the console:
In the compiled code, the
customElements.define
call looks like this:This does not seem to happen when building in non-dev mode.
Reproduction
Here is a basic example:
And here is a REPL: https://svelte.dev/repl/c66893a2ff384eac854af6ec4bf10810?version=4.0.5
Please turn on
customElements
anddev
in compiler options.Logs
Uncaught TypeError: can't redefine non-configurable property "increment"
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: