From 645d710b917da350dafa65cbcc14b2f38cec46b8 Mon Sep 17 00:00:00 2001 From: Jared Dunham Date: Tue, 16 Apr 2024 07:12:37 -0500 Subject: [PATCH] Fix Svelte 4 slot rendering issues (#1763) * Moved svelte:component into key block * Formatting --------- Co-authored-by: Jonathan Reinink --- packages/svelte/src/Render.svelte | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/svelte/src/Render.svelte b/packages/svelte/src/Render.svelte index db30c2df4..f33cca93f 100644 --- a/packages/svelte/src/Render.svelte +++ b/packages/svelte/src/Render.svelte @@ -14,12 +14,23 @@ export let component export let props = {} export let children = [] + + let prevComponent + let key + $: { + if (prevComponent !== component) { + key = Date.now() + prevComponent = component + } + } {#if $store.component} - - {#each children as child, index (component && component.length === index ? $store.key : null)} - - {/each} - + {#key key} + + {#each children as child, index (component && component.length === index ? $store.key : null)} + + {/each} + + {/key} {/if}