Skip to content

Commit 4cb616a

Browse files
committed
Merge remote-tracking branch 'origin/allozaur/svelte-webui' into allozaur/svelte-webui
2 parents af8b1cd + 5ba666e commit 4cb616a

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

tools/server/webui/src/routes/chat/[id]/+page.svelte

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,47 @@
1717
let chatId = $derived($page.params.id);
1818
let currentChatId: string | undefined = undefined;
1919
20-
// Navigation guard to handle streaming abortion
2120
beforeNavigate(async ({ cancel, to }) => {
22-
// Check if we're currently streaming a response
2321
if (isLoading()) {
2422
console.log(
2523
'Navigation detected while streaming - aborting stream and saving partial response'
2624
);
2725
28-
// Cancel navigation temporarily to allow cleanup
2926
cancel();
3027
31-
// Gracefully stop generation and save partial response
3228
await gracefulStop();
3329
34-
// Now proceed with navigation
3530
if (to?.url) {
3631
await goto(to.url.pathname + to.url.search);
3732
}
3833
}
3934
});
4035
41-
// Load chat when ID changes
4236
$effect(() => {
4337
if (chatId && chatId !== currentChatId) {
44-
// If we're switching chats and currently streaming, abort first
4538
if (isLoading()) {
4639
console.log('Chat switch detected while streaming - aborting stream');
4740
stopGeneration();
4841
}
4942
5043
currentChatId = chatId;
5144
52-
// Load the chat asynchronously
5345
(async () => {
5446
const success = await chatStore.loadConversation(chatId);
47+
5548
if (!success) {
56-
// Chat not found, redirect to home
5749
await goto('/');
5850
}
5951
})();
6052
}
6153
});
6254
63-
// Handle page unload (refresh, close tab, etc.)
6455
$effect(() => {
6556
if (typeof window !== 'undefined') {
6657
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
6758
if (isLoading()) {
6859
console.log('Page unload detected while streaming - aborting stream');
6960
stopGeneration();
70-
// Note: We can't wait for async operations in beforeunload
71-
// but stopGeneration() will attempt to save synchronously
7261
}
7362
};
7463
@@ -80,10 +69,8 @@
8069
}
8170
});
8271
83-
// Cleanup on component destroy
8472
onDestroy(() => {
8573
if (isLoading()) {
86-
console.log('Component destroying while streaming - aborting stream');
8774
stopGeneration();
8875
}
8976
});

0 commit comments

Comments
 (0)