From 7b80dabfe25fbcdf26e880ddf518a39d9f8fb230 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 15 Nov 2022 12:58:52 +0000 Subject: [PATCH] Disregard block components from ejection which are unmounted during parent blocks lifecycles --- packages/client/src/components/Block.svelte | 11 ++++++++++- packages/client/src/components/BlockComponent.svelte | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/Block.svelte b/packages/client/src/components/Block.svelte index 75474dfd6f..8258912e52 100644 --- a/packages/client/src/components/Block.svelte +++ b/packages/client/src/components/Block.svelte @@ -9,7 +9,7 @@ let structureLookupMap = {} const registerBlockComponent = (id, order, parentId, instance) => { - // Ensure child array exists + // Ensure child map exists if (!structureLookupMap[parentId]) { structureLookupMap[parentId] = {} } @@ -18,6 +18,14 @@ structureLookupMap[parentId][order] = instance } + const unregisterBlockComponent = (order, parentId) => { + // Ensure child map exists + if (!structureLookupMap[parentId]) { + return + } + delete structureLookupMap[parentId][order] + } + const eject = () => { // Start the new structure with the root component let definition = structureLookupMap[$component.id][0] @@ -73,6 +81,7 @@ // We register block components with their raw props so that we can eject // blocks later on registerComponent: registerBlockComponent, + unregisterComponent: unregisterBlockComponent, }) onMount(() => { diff --git a/packages/client/src/components/BlockComponent.svelte b/packages/client/src/components/BlockComponent.svelte index 2f756ce296..0131c5f0d4 100644 --- a/packages/client/src/components/BlockComponent.svelte +++ b/packages/client/src/components/BlockComponent.svelte @@ -1,5 +1,5 @@