diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 20b13b781b..fe01dd781f 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1962,6 +1962,10 @@ }); } + if ($page.url.pathname === '/' || $page.url.pathname.startsWith('/folders/')) { + tick().then(initNewChat); + } + // the artifacts pane reads this list when it opens, which can be before the debounced rebuild const showArtifactsSubscribe = showArtifacts.subscribe((value) => { if (value) getContents(); @@ -2494,8 +2498,12 @@ return () => bridge?.end(); }); // Only real navigation resets the chat; shallow sidebar state changes must preserve it. - afterNavigate(async ({ to }) => { - if (to?.url.pathname === '/' || to?.url.pathname.startsWith('/folders/')) { + afterNavigate(async ({ from, to }) => { + // A navigation that mounts this page starts its new chat in onMount. + if ( + from?.route.id === to?.route.id && + (to?.url.pathname === '/' || to?.url.pathname.startsWith('/folders/')) + ) { await tick(); initNewChat(); }