diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index 38666d13d9..4c94c86c1d 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -181,13 +181,14 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { const handleConversationIdInfoChange = useCallback((changeConversationId: string) => { if (appId) { setConversationIdInfo((prev) => { - let prevValue = prev?.[appId || ''] - if (typeof prevValue === 'string') - prevValue = {} + const prevAppConversations = prev?.[appId || ''] + const base = typeof prevAppConversations === 'object' && prevAppConversations + ? prevAppConversations + : {} return { ...prev, [appId || '']: { - ...prevValue, + ...base, [userId || 'DEFAULT']: changeConversationId, }, } diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 281a1658e7..dafe608fb0 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -147,13 +147,14 @@ export const useEmbeddedChatbot = (appSourceType: AppSourceType, tryAppId?: stri const handleConversationIdInfoChange = useCallback((changeConversationId: string) => { if (appId) { setConversationIdInfo((prev) => { - let prevValue = prev?.[appId || ''] - if (typeof prevValue === 'string') - prevValue = {} + const prevAppConversations = prev?.[appId || ''] + const base = typeof prevAppConversations === 'object' && prevAppConversations + ? prevAppConversations + : {} return { ...prev, [appId || '']: { - ...prevValue, + ...base, [userId || 'DEFAULT']: changeConversationId, }, }