fix: abort chat make page error
This commit is contained in:
parent
d0e65431d0
commit
1f801d1464
@ -57,6 +57,8 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
|
|
||||||
// 中断请求
|
// 中断请求
|
||||||
const controller = useRef(new AbortController());
|
const controller = useRef(new AbortController());
|
||||||
|
const isResetPage = useRef(false);
|
||||||
|
|
||||||
const [chatData, setChatData] = useState<ChatType>({
|
const [chatData, setChatData] = useState<ChatType>({
|
||||||
chatId,
|
chatId,
|
||||||
modelId,
|
modelId,
|
||||||
@ -166,7 +168,9 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
const resetChat = useCallback(
|
const resetChat = useCallback(
|
||||||
async (modelId = chatData.modelId, chatId = '') => {
|
async (modelId = chatData.modelId, chatId = '') => {
|
||||||
// 强制中断流
|
// 强制中断流
|
||||||
|
isResetPage.current = true;
|
||||||
controller.current?.abort();
|
controller.current?.abort();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
router.replace(`/chat?modelId=${modelId}&chatId=${chatId}`);
|
router.replace(`/chat?modelId=${modelId}&chatId=${chatId}`);
|
||||||
loadChatInfo({
|
loadChatInfo({
|
||||||
@ -199,6 +203,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
// create abort obj
|
// create abort obj
|
||||||
const abortSignal = new AbortController();
|
const abortSignal = new AbortController();
|
||||||
controller.current = abortSignal;
|
controller.current = abortSignal;
|
||||||
|
isResetPage.current = false;
|
||||||
|
|
||||||
const prompt = {
|
const prompt = {
|
||||||
obj: prompts.obj,
|
obj: prompts.obj,
|
||||||
@ -229,6 +234,11 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
abortSignal
|
abortSignal
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 重置了页面,说明退出了当前聊天, 不缓存任何内容
|
||||||
|
if (isResetPage.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let newChatId = '';
|
let newChatId = '';
|
||||||
// 保存对话信息
|
// 保存对话信息
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user