From 45b07518262256029dc4c8013088b4064b82d662 Mon Sep 17 00:00:00 2001 From: twwu Date: Mon, 20 Apr 2026 17:17:42 +0800 Subject: [PATCH] fix(chat): add abort mechanism for in-flight requests on unmount --- web/app/components/base/chat/chat/hooks.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/web/app/components/base/chat/chat/hooks.ts b/web/app/components/base/chat/chat/hooks.ts index dad42bcadb..d19a784d41 100644 --- a/web/app/components/base/chat/chat/hooks.ts +++ b/web/app/components/base/chat/chat/hooks.ts @@ -209,6 +209,19 @@ export const useChat = ( cb?.() }, [handleStop]) + const abortInflightRequests = useCallback(() => { + conversationMessagesAbortControllerRef.current?.abort() + suggestedQuestionsAbortControllerRef.current?.abort() + workflowEventsAbortControllerRef.current?.abort() + }, []) + + // Abort all in-flight fetch/SSE requests when the consumer unmounts + useEffect(() => { + return () => { + abortInflightRequests() + } + }, [abortInflightRequests]) + const createAudioPlayerManager = useCallback(() => { let ttsUrl = '' let ttsIsPublic = false