diff --git a/.changeset/olive-apples-lick.md b/.changeset/olive-apples-lick.md new file mode 100644 index 0000000000..207a88f306 --- /dev/null +++ b/.changeset/olive-apples-lick.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: check if svelte component exists on custom element destroy diff --git a/packages/svelte/src/internal/client/dom/elements/custom-element.js b/packages/svelte/src/internal/client/dom/elements/custom-element.js index eb47d674c2..36b4ff6afd 100644 --- a/packages/svelte/src/internal/client/dom/elements/custom-element.js +++ b/packages/svelte/src/internal/client/dom/elements/custom-element.js @@ -193,7 +193,7 @@ if (typeof HTMLElement === 'function') { this.$$cn = false; // In a microtask, because this could be a move within the DOM Promise.resolve().then(() => { - if (!this.$$cn) { + if (!this.$$cn && this.$$c) { this.$$c.$destroy(); destroy_effect(this.$$me); this.$$c = undefined;