diff --git a/.changeset/many-trainers-pretend.md b/.changeset/many-trainers-pretend.md new file mode 100644 index 0000000000..207a88f306 --- /dev/null +++ b/.changeset/many-trainers-pretend.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: check if svelte component exists on custom element destroy diff --git a/packages/svelte/src/runtime/internal/Component.js b/packages/svelte/src/runtime/internal/Component.js index e417176421..a0b0f58172 100644 --- a/packages/svelte/src/runtime/internal/Component.js +++ b/packages/svelte/src/runtime/internal/Component.js @@ -335,7 +335,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(); this.$$c = undefined; }