diff --git a/app/store/chat.ts b/app/store/chat.ts index 048dbe31e..b7e50b4c9 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -221,14 +221,16 @@ export const useChatStore = create()( { text: Locale.Home.Revert, onClick() { - const sessions = get().sessions; - // if the deleted session is the only session in sessions array, - // we should delete the empty session first before inserting the deleted session - sessions.splice(index, isLastSession, deletedSession); - set(() => ({ - sessions: sessions, - currentSessionIndex: seletedSessionIndex, - })); + set((state) => { + const newSessions = [...state.sessions]; + // if the deleted session is the only session in sessions array, + // we should delete the empty session first before inserting the deleted session + newSessions.splice(index, isLastSession, deletedSession); + return { + sessions: newSessions, + currentSessionIndex: seletedSessionIndex, + }; + }); }, }, 5000,