mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 12:32:30 +08:00
### 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:
@ -257,25 +257,32 @@ export const useSendMessageWithSse = (
|
|||||||
.getReader();
|
.getReader();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const x = await reader?.read();
|
try {
|
||||||
if (x) {
|
const x = await reader?.read();
|
||||||
const { done, value } = x;
|
if (x) {
|
||||||
if (done) {
|
const { done, value } = x;
|
||||||
resetAnswer();
|
if (done) {
|
||||||
break;
|
resetAnswer();
|
||||||
}
|
break;
|
||||||
try {
|
|
||||||
const val = JSON.parse(value?.data || '');
|
|
||||||
const d = val?.data;
|
|
||||||
if (typeof d !== 'boolean') {
|
|
||||||
setAnswer({
|
|
||||||
...d,
|
|
||||||
conversationId: body?.conversation_id,
|
|
||||||
chatBoxId: body.chatBoxId,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
try {
|
||||||
// Swallow parse errors silently
|
const val = JSON.parse(value?.data || '');
|
||||||
|
const d = val?.data;
|
||||||
|
if (typeof d !== 'boolean') {
|
||||||
|
setAnswer({
|
||||||
|
...d,
|
||||||
|
conversationId: body?.conversation_id,
|
||||||
|
chatBoxId: body.chatBoxId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Swallow parse errors silently
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof DOMException && e.name === 'AbortError') {
|
||||||
|
console.log('Request was aborted by user or logic.');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,29 +126,36 @@ export const useSendMessageBySSE = (url: string = api.completeConversation) => {
|
|||||||
.getReader();
|
.getReader();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const x = await reader?.read();
|
try {
|
||||||
if (x) {
|
const x = await reader?.read();
|
||||||
const { done, value } = x;
|
if (x) {
|
||||||
if (done) {
|
const { done, value } = x;
|
||||||
console.info('done');
|
if (done) {
|
||||||
resetAnswerList();
|
console.info('done');
|
||||||
break;
|
resetAnswerList();
|
||||||
}
|
break;
|
||||||
try {
|
|
||||||
const val = JSON.parse(value?.data || '');
|
|
||||||
|
|
||||||
console.info('data:', val);
|
|
||||||
if (val.code === 500) {
|
|
||||||
message.error(val.message);
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
const val = JSON.parse(value?.data || '');
|
||||||
|
|
||||||
setAnswerList((list) => {
|
console.info('data:', val);
|
||||||
const nextList = [...list];
|
if (val.code === 500) {
|
||||||
nextList.push(val);
|
message.error(val.message);
|
||||||
return nextList;
|
}
|
||||||
});
|
|
||||||
} catch (e) {
|
setAnswerList((list) => {
|
||||||
console.warn(e);
|
const nextList = [...list];
|
||||||
|
nextList.push(val);
|
||||||
|
return nextList;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof DOMException && e.name === 'AbortError') {
|
||||||
|
console.log('Request was aborted by user or logic.');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -382,9 +382,9 @@ export const useSendAgentMessage = ({
|
|||||||
const { content, id } = findMessageFromList(answerList);
|
const { content, id } = findMessageFromList(answerList);
|
||||||
const inputAnswer = findInputFromList(answerList);
|
const inputAnswer = findInputFromList(answerList);
|
||||||
const answer = content || getLatestError(answerList);
|
const answer = content || getLatestError(answerList);
|
||||||
if (answerList.length > 0 && answer) {
|
if (answerList.length > 0) {
|
||||||
addNewestOneAnswer({
|
addNewestOneAnswer({
|
||||||
answer: answer,
|
answer: answer ?? '',
|
||||||
id: id,
|
id: id,
|
||||||
...inputAnswer,
|
...inputAnswer,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export function useUploadFile() {
|
|||||||
if (Array.isArray(files) && files.length) {
|
if (Array.isArray(files) && files.length) {
|
||||||
const file = files[0];
|
const file = files[0];
|
||||||
const ret = await uploadAndParseFile({ file, options, conversationId });
|
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]);
|
setFileIds((list) => [...list, ...ret.data]);
|
||||||
setFileMap((map) => {
|
setFileMap((map) => {
|
||||||
map.set(files[0], ret.data[0]);
|
map.set(files[0], ret.data[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user