From 1bab571caa9f1bc86443d830a10dd8ee9dbff973 Mon Sep 17 00:00:00 2001 From: Philipp Pracht Date: Mon, 6 May 2024 16:01:01 +0200 Subject: [PATCH] fix: additional check for component on destroy (svelte4) (#11489) fixes #10454 --- .changeset/many-trainers-pretend.md | 5 +++++ packages/svelte/src/runtime/internal/Component.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/many-trainers-pretend.md 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; }