Fix: Clicking "Stop receiving messages" in Firefox will cause the page to crash. #10752 (#10754)

### What problem does this PR solve?

Fix: Clicking "Stop receiving messages" in Firefox will cause the page
to crash. #10752
### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu
2025-10-23 16:17:28 +08:00
committed by GitHub
parent 6d333ec4bc
commit 37004ecfb3
4 changed files with 56 additions and 42 deletions

View File

@ -257,6 +257,7 @@ export const useSendMessageWithSse = (
.getReader();
while (true) {
try {
const x = await reader?.read();
if (x) {
const { done, value } = x;
@ -278,6 +279,12 @@ export const useSendMessageWithSse = (
// Swallow parse errors silently
}
}
} catch (e) {
if (e instanceof DOMException && e.name === 'AbortError') {
console.log('Request was aborted by user or logic.');
break;
}
}
}
setDoneValue(body, true);
resetAnswer();

View File

@ -126,6 +126,7 @@ export const useSendMessageBySSE = (url: string = api.completeConversation) => {
.getReader();
while (true) {
try {
const x = await reader?.read();
if (x) {
const { done, value } = x;
@ -151,6 +152,12 @@ export const useSendMessageBySSE = (url: string = api.completeConversation) => {
console.warn(e);
}
}
} catch (e) {
if (e instanceof DOMException && e.name === 'AbortError') {
console.log('Request was aborted by user or logic.');
break;
}
}
}
console.info('done?');
setDone(true);

View File

@ -382,9 +382,9 @@ export const useSendAgentMessage = ({
const { content, id } = findMessageFromList(answerList);
const inputAnswer = findInputFromList(answerList);
const answer = content || getLatestError(answerList);
if (answerList.length > 0 && answer) {
if (answerList.length > 0) {
addNewestOneAnswer({
answer: answer,
answer: answer ?? '',
id: id,
...inputAnswer,
});

View File

@ -20,7 +20,7 @@ export function useUploadFile() {
if (Array.isArray(files) && files.length) {
const file = files[0];
const ret = await uploadAndParseFile({ file, options, conversationId });
if (ret.code === 0 && Array.isArray(ret.data)) {
if (ret?.code === 0 && Array.isArray(ret?.data)) {
setFileIds((list) => [...list, ...ret.data]);
setFileMap((map) => {
map.set(files[0], ret.data[0]);