diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 7d5e131d2..b510dd0b6 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -934,15 +934,19 @@ } }; - $: if (history) { - cancelAnimationFrame(contentsRAF); - contentsRAF = requestAnimationFrame(() => { - getContents(); - contentsRAF = null; - }); - } else { - artifactContents.set([]); - } + const onHistoryChange = (history) => { + if (history) { + cancelAnimationFrame(contentsRAF); + contentsRAF = requestAnimationFrame(() => { + getContents(); + contentsRAF = null; + }); + } else { + artifactContents.set([]); + } + }; + + $: onHistoryChange(history); const getContents = () => { const messages = history ? createMessagesList(history, history.currentId) : [];