From 6076afd5f5b99435b73b51cba0b3b52769e6a740 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 11 Jun 2025 20:16:53 +0400 Subject: [PATCH] fix: url param issue #14901 --- src/lib/components/chat/Chat.svelte | 20 +++++--------------- src/lib/components/layout/Sidebar.svelte | 2 ++ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 89fa81462..bd12ef35d 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -432,31 +432,20 @@ } }; + let pageSubscribe = null; onMount(async () => { loading = true; console.log('mounted'); window.addEventListener('message', onMessageHandler); $socket?.on('chat-events', chatEventHandler); - page.subscribe((page) => { - if (page.url.pathname === '/') { + pageSubscribe = page.subscribe(async (p) => { + if (p.url.pathname === '/') { + await tick(); initNewChat(); } }); - if (!$chatId) { - chatIdUnsubscriber = chatId.subscribe(async (value) => { - if (!value) { - await tick(); // Wait for DOM updates - await initNewChat(); - } - }); - } else { - if ($temporaryChatEnabled) { - await goto('/'); - } - } - if (localStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)) { prompt = ''; files = []; @@ -515,6 +504,7 @@ }); onDestroy(() => { + pageSubscribe(); chatIdUnsubscriber?.(); window.removeEventListener('message', onMessageHandler); $socket?.off('chat-events', chatEventHandler); diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index e456c303a..6a6e4b3af 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -490,6 +490,8 @@ draggable="false" on:click={async () => { selectedChatId = null; + + await temporaryChatEnabled.set(false); await goto('/'); const newChatButton = document.getElementById('new-chat-button'); setTimeout(() => {