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