Skip to content

Commit c8b9b8c

Browse files
chat conversation issue fix
1 parent 0fefa51 commit c8b9b8c

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/App/src/hooks/useChatApi.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ export const useChatApi = ({
8080
const abortControllersRef = useRef<AbortController[]>([]);
8181

8282
useEffect(() => {
83-
if (!generatingResponse && !isStreamingInProgress) {
84-
return;
83+
if (generatingResponse || isStreamingInProgress) {
84+
const chatAPISignal = abortControllersRef.current.shift();
85+
chatAPISignal?.abort(
86+
"Chat Aborted due to switch to other conversation while generating"
87+
);
8588
}
86-
87-
const currentRequest = abortControllersRef.current.shift();
88-
currentRequest?.abort(
89-
"Chat aborted due to switching to another conversation."
90-
);
91-
}, [generatingResponse, isStreamingInProgress, selectedConversationId]);
89+
// eslint-disable-next-line react-hooks/exhaustive-deps
90+
}, [selectedConversationId]);
9291

9392
const readStreamingResponse = useCallback(
9493
async (
@@ -404,13 +403,15 @@ export const useChatApi = ({
404403
onToolDelta: (content) => {
405404
streamMessage.citations = content;
406405
if (!isChart) {
406+
dispatch(setStreamingInProgress(true));
407407
dispatch(updateMessageById({ ...streamMessage }));
408408
}
409409
},
410410
onAssistantDelta: (content) => {
411411
if (!isChart) {
412412
streamMessage.content = content;
413413
streamMessage.role = ASSISTANT;
414+
dispatch(setStreamingInProgress(true));
414415
dispatch(updateMessageById({ ...streamMessage }));
415416
scrollChatToBottom();
416417
}

0 commit comments

Comments
 (0)