From 981ec89e15d22e430dc59133bd80f42379f8de97 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 17 Jan 2024 19:42:40 -0800 Subject: [PATCH] fix: cancel chat generation on route change --- src/routes/(app)/+page.svelte | 5 +++++ src/routes/(app)/c/[id]/+page.svelte | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index 2f3983a3..93b50a32 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -80,6 +80,11 @@ ////////////////////////// const initNewChat = async () => { + if (currentRequestId !== null) { + await cancelChatCompletion(localStorage.token, currentRequestId); + currentRequestId = null; + } + window.history.replaceState(history.state, '', `/`); console.log('initNewChat'); diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index 9a073935..412c332e 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -705,7 +705,12 @@ 0} - initNewChat={() => { + initNewChat={async () => { + if (currentRequestId !== null) { + await cancelChatCompletion(localStorage.token, currentRequestId); + currentRequestId = null; + } + goto('/'); }} />