From 9862a5bd613bb1c98166bb0eff1c8e824fa86723 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Tue, 20 Oct 2026 13:16:11 -0400 Subject: [PATCH] fix: Preview on an earlier block opens that block's artifact when the pane was closed (#32688) --- src/lib/components/chat/Artifacts.svelte | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib/components/chat/Artifacts.svelte b/src/lib/components/chat/Artifacts.svelte index 98b6604b03..1b08a257b0 100644 --- a/src/lib/components/chat/Artifacts.svelte +++ b/src/lib/components/chat/Artifacts.svelte @@ -92,13 +92,6 @@ }; onMount(() => { - const unsubscribeArtifactCode = artifactCode.subscribe((value) => { - if (contents) { - const codeIdx = contents.findIndex((content) => content.content.includes(value)); - selectedContentIdx = codeIdx !== -1 ? codeIdx : 0; - } - }); - const unsubscribeArtifactContents = artifactContents.subscribe((value) => { const newContents = value ?? []; console.log('Artifact contents updated:', newContents); @@ -116,9 +109,17 @@ contents = newContents; }); + const unsubscribeArtifactCode = artifactCode.subscribe((value) => { + if (contents && value) { + const codeIdx = contents.findIndex((content) => content.content.includes(value)); + selectedContentIdx = codeIdx !== -1 ? codeIdx : 0; + } + }); + return () => { unsubscribeArtifactCode(); unsubscribeArtifactContents(); + artifactCode.set(null); }; });