fix: url param issue

#14901
This commit is contained in:
Timothy Jaeryang Baek 2025-06-11 20:16:53 +04:00
parent 387c2377ba
commit 6076afd5f5
2 changed files with 7 additions and 15 deletions

View File

@ -432,31 +432,20 @@
} }
}; };
let pageSubscribe = null;
onMount(async () => { onMount(async () => {
loading = true; loading = true;
console.log('mounted'); console.log('mounted');
window.addEventListener('message', onMessageHandler); window.addEventListener('message', onMessageHandler);
$socket?.on('chat-events', chatEventHandler); $socket?.on('chat-events', chatEventHandler);
page.subscribe((page) => { pageSubscribe = page.subscribe(async (p) => {
if (page.url.pathname === '/') { if (p.url.pathname === '/') {
await tick();
initNewChat(); 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}` : ''}`)) { if (localStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)) {
prompt = ''; prompt = '';
files = []; files = [];
@ -515,6 +504,7 @@
}); });
onDestroy(() => { onDestroy(() => {
pageSubscribe();
chatIdUnsubscriber?.(); chatIdUnsubscriber?.();
window.removeEventListener('message', onMessageHandler); window.removeEventListener('message', onMessageHandler);
$socket?.off('chat-events', chatEventHandler); $socket?.off('chat-events', chatEventHandler);

View File

@ -490,6 +490,8 @@
draggable="false" draggable="false"
on:click={async () => { on:click={async () => {
selectedChatId = null; selectedChatId = null;
await temporaryChatEnabled.set(false);
await goto('/'); await goto('/');
const newChatButton = document.getElementById('new-chat-button'); const newChatButton = document.getElementById('new-chat-button');
setTimeout(() => { setTimeout(() => {