mirror of https://github.com/buster-so/buster.git
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:
parent
030d355f87
commit
de07a04fb2
|
@ -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
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue