From de07a04fb2f1f63e166091586db64f65c995806c Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 24 Sep 2025 14:02:01 +0000 Subject: [PATCH] Fix automatic navigation bug when returning to tab after report completion - Integrate useWindowFocus hook to detect when user returns to tab - Add forceNavigationCheck ref to trigger navigation re-evaluation on window focus - Modify completion detection logic to handle focus-based navigation triggers - Maintains existing navigation behavior while fixing stuck reasoning view issue Fixes BUS-1908 Co-Authored-By: nate@buster.so --- .../useAutoRedirectStreaming.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useAutoRedirectStreaming.ts b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useAutoRedirectStreaming.ts index e10556d1b..df90242b0 100644 --- a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useAutoRedirectStreaming.ts +++ b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useAutoRedirectStreaming.ts @@ -9,6 +9,7 @@ import { useGetChatMessageIsFinishedReasoning, useGetChatMessageLastReasoningMessageId, } from '@/context/Chats/useGetChatMessage'; +import { useWindowFocus } from '@/hooks/useWindowFocus'; import { assetParamsToRoute } from '@/lib/assets/assetParamsToRoute'; export const useAutoRedirectStreaming = ({ @@ -28,6 +29,7 @@ export const useAutoRedirectStreaming = ({ const hasResponseFile = useGetChatMessageHasResponseFile({ messageId: lastMessageId }); const previousIsCompletedStream = useRef(isStreamFinished); + const forceNavigationCheck = useRef(false); const hasLoadedChat = useHasLoadedChat({ chatId: chatId || '' }); @@ -37,6 +39,12 @@ export const useAutoRedirectStreaming = ({ previousIsCompletedStream.current = isStreamFinished; }, [hasLoadedChat]); + useWindowFocus(() => { + if (hasLoadedChat && chatId) { + forceNavigationCheck.current = true; + } + }); + //streaming logic to redirect useEffect(() => { if (!hasLoadedChat || !chatId) { @@ -72,7 +80,7 @@ export const useAutoRedirectStreaming = ({ navigate({ to: '/app/chats/$chatId/reasoning/$messageId', params: { - chatId, + chatId: chatId, messageId: lastMessageId, }, replace: true, @@ -83,7 +91,7 @@ export const useAutoRedirectStreaming = ({ else if ( isFinishedReasoning && isStreamFinished && - previousIsCompletedStream.current === false && + (previousIsCompletedStream.current === false || forceNavigationCheck.current) && !firstFileId ) { //no file is found, so we need to collapse the chat @@ -91,10 +99,12 @@ export const useAutoRedirectStreaming = ({ navigate({ to: '/app/chats/$chatId', params: { - chatId, + chatId: chatId, }, replace: true, }); + + forceNavigationCheck.current = false; } - }, [isStreamFinished, hasReasoning, hasResponseFile, chatId, lastMessageId, isFinishedReasoning]); //only use these values to trigger the useEffect + }, [isStreamFinished, hasReasoning, hasResponseFile, chatId, lastMessageId, isFinishedReasoning, forceNavigationCheck.current]); //only use these values to trigger the useEffect };