From 7f517a944f3fd5c5ca84550f6a0f6de14efe4310 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Fri, 13 Mar 2026 09:59:31 +0800 Subject: [PATCH] refactor: use const instead of let reassignment in state updater Replace mutable let variable with const declarations for the previous app conversations lookup, making the functional state update logic more declarative. Signed-off-by: majiayu000 <1835304752@qq.com> --- web/app/components/base/chat/chat-with-history/hooks.tsx | 9 +++++---- web/app/components/base/chat/embedded-chatbot/hooks.tsx | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) 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, }, }