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 <nate@buster.so>
This commit is contained in:
Devin AI 2025-09-24 14:02:01 +00:00
parent 030d355f87
commit de07a04fb2
1 changed files with 14 additions and 4 deletions

View File

@ -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<boolean>(isStreamFinished);
const forceNavigationCheck = useRef<boolean>(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
};