From 489b56beb874f91e412458a26dbb7e07867a9e83 Mon Sep 17 00:00:00 2001 From: wyysf123 <52561586+wyysf123@users.noreply.github.com> Date: Wed, 9 Mar 2022 19:51:46 +0800 Subject: [PATCH] fixed customElements.define error When using svelte to create webcomponents components, I found a problem. For example, I created an Icon component first, and then used it for both the Dialog component and the Button component. At this time, an error will be reported saying that the Icon component has been repeatedly defined. To find the cause of the error in the source code of svelte, just modify this code to: ""if (component.tag ! = null) { body.push(b !@_customElements.get("${component.tag}") && @_customElements.define("${component.tag}", ${name});); --- src/compiler/compile/render_dom/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 9d9699bdbf6c..d1c5c645dc39 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -569,7 +569,7 @@ export default function dom( if (component.tag != null) { body.push(b` - @_customElements.define("${component.tag}", ${name}); + !@_customElements.get("${component.tag}") && @_customElements.define("${component.tag}", ${name}); `); } } else {