Skip to content
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

SvelteElement attempts to redefine itself when reloading after HMR update #6164

Closed
lorrenbiffin opened this issue Apr 3, 2021 · 3 comments
Closed

Comments

@lorrenbiffin
Copy link

lorrenbiffin commented Apr 3, 2021

Svelte's compiler attempts customElements.define(..) at the end of each generated SvelteElement when customElement: true and tag="tag-name" are set.

When used in an environment which uses HMR, this causes the following error:

hmr-client.js:218 [ESM-HMR] Hot Update Error DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "custom-element-example" has already been used with this registry

The "offending" line is here:

@_customElements.define("${component.tag}", ${name});


Reproduce:

  1. Setup a new Svelte project with HMR. I've used Snowpack with @snowpack/svelte-plugin.
  2. Set customElement: true in compiler options, like so:
// svelte.config.js
module.exports = {
  compilerOptions: {
    customElement: true,
  },
};
  1. In a .svelte component file, add tag="tag-name" to svelte:options, like so:
<svelte:options tag="custom-element-example"/>

<div id="custom-element-example">
  Some content ..
</div>
  1. Compile your project and run it in browser with console open.
  2. Make a change and save it (to trigger an HMR update)
  3. Observe console error.

Expected Behavior:

Svelte component should be recompiled and properly reregistered within the document scope.

@stale
Copy link

stale bot commented Jul 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Jul 6, 2021
@stale
Copy link

stale bot commented Jul 20, 2021

This issue has been closed as it was previously marked as stale and saw no subsequent activity.

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

No branches or pull requests

1 participant