From 1f801d14640232fcc780f9c3b952562a8ef289ab Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Tue, 25 Apr 2023 23:47:24 +0800 Subject: [PATCH] fix: abort chat make page error --- src/pages/chat/index.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pages/chat/index.tsx b/src/pages/chat/index.tsx index 80e62b6d3..0a2d7a82d 100644 --- a/src/pages/chat/index.tsx +++ b/src/pages/chat/index.tsx @@ -57,6 +57,8 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => { // 中断请求 const controller = useRef(new AbortController()); + const isResetPage = useRef(false); + const [chatData, setChatData] = useState({ chatId, modelId, @@ -166,7 +168,9 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => { const resetChat = useCallback( async (modelId = chatData.modelId, chatId = '') => { // 强制中断流 + isResetPage.current = true; controller.current?.abort(); + try { router.replace(`/chat?modelId=${modelId}&chatId=${chatId}`); loadChatInfo({ @@ -199,6 +203,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => { // create abort obj const abortSignal = new AbortController(); controller.current = abortSignal; + isResetPage.current = false; const prompt = { obj: prompts.obj, @@ -229,6 +234,11 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => { abortSignal }); + // 重置了页面,说明退出了当前聊天, 不缓存任何内容 + if (isResetPage.current) { + return; + } + let newChatId = ''; // 保存对话信息 try {