mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
fix: abort chat make page error
This commit is contained in:
@@ -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<ChatType>({
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user