From 3e1f82b8c4b2df3597f98e24e3d4e20bb1f35e7f Mon Sep 17 00:00:00 2001 From: Philipp Pracht Date: Mon, 6 May 2024 16:00:09 +0200 Subject: [PATCH] fix: additional check for component on destroy (#11488) fixes #10454 --- .changeset/olive-apples-lick.md | 5 +++++ .../src/internal/client/dom/elements/custom-element.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/olive-apples-lick.md 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;