From 790adb2d12f6f70e78d5d278a8577f8a1628e1e1 Mon Sep 17 00:00:00 2001 From: Dogtiti <499960698@qq.com> Date: Mon, 11 Nov 2024 16:03:26 +0800 Subject: [PATCH] fix: rerender chat component --- app/components/chat.tsx | 4 ++-- app/store/chat.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index ed51d926f4e..8e01d43b8d1 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -2071,6 +2071,6 @@ function _Chat() { export function Chat() { const chatStore = useChatStore(); - const sessionIndex = chatStore.currentSessionIndex; - return <_Chat key={sessionIndex}>; + const forceUpdateKey = chatStore.forceUpdateKey; + return <_Chat key={forceUpdateKey}>; } diff --git a/app/store/chat.ts b/app/store/chat.ts index 63d7394ece6..27d4eb1674b 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -193,6 +193,7 @@ const DEFAULT_CHAT_STATE = { sessions: [createEmptySession()], currentSessionIndex: 0, lastInput: "", + forceUpdateKey: Date.now(), }; export const useChatStore = createPersistStore( @@ -225,6 +226,7 @@ export const useChatStore = createPersistStore( set((state) => ({ currentSessionIndex: 0, sessions: [newSession, ...state.sessions], + forceUpdateKey: Date.now(), })); }, @@ -232,12 +234,14 @@ export const useChatStore = createPersistStore( set(() => ({ sessions: [createEmptySession()], currentSessionIndex: 0, + forceUpdateKey: Date.now(), })); }, selectSession(index: number) { set({ currentSessionIndex: index, + forceUpdateKey: Date.now(), }); }, @@ -262,6 +266,7 @@ export const useChatStore = createPersistStore( return { currentSessionIndex: newIndex, sessions: newSessions, + forceUpdateKey: Date.now(), }; }); }, @@ -286,6 +291,7 @@ export const useChatStore = createPersistStore( set((state) => ({ currentSessionIndex: 0, sessions: [session].concat(state.sessions), + forceUpdateKey: Date.now(), })); }, @@ -325,6 +331,7 @@ export const useChatStore = createPersistStore( set(() => ({ currentSessionIndex: nextIndex, sessions, + forceUpdateKey: Date.now(), })); showToast(