From 91dcecd2b9c5edd4587442642a8527f2812bc168 Mon Sep 17 00:00:00 2001 From: chanx <1243304602@qq.com> Date: Wed, 5 Aug 2026 17:11:33 +0800 Subject: [PATCH] Fix: applying model config in one multi-chat card no longer overrides sibling cards (#17866) --- .../chat/chat-box/next-multiple-chat-box.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.tsx b/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.tsx index 22cf808fd4..634404f5ff 100644 --- a/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.tsx +++ b/web/src/pages/next-chats/chat/chat-box/next-multiple-chat-box.tsx @@ -158,9 +158,22 @@ const ChatCard = forwardRef(function ChatCard( const { data: currentDialog } = useFetchChat(); const findLlmByUuid = useFindLlmByUuid(); + // Each card must keep its own independently selected model after the initial + // sync. Without this guard, clicking "Apply" in one card patches the dialog + // (which invalidates [FetchChat] and refetches currentDialog), and the + // changed currentDialog.llm_id would then overwrite every other card's + // llm_id via this effect. Sync only when dialogId changes (initial load or + // conversation switch), not when currentDialog.llm_id changes due to Apply. + const syncedDialogIdRef = useRef(undefined); useLayoutEffect(() => { - form.setValue('llm_id', currentDialog?.llm_id || ''); - }, [currentDialog?.llm_id, form]); + if ( + syncedDialogIdRef.current !== dialogId && + currentDialog?.llm_id + ) { + form.setValue('llm_id', currentDialog.llm_id); + syncedDialogIdRef.current = dialogId; + } + }, [currentDialog?.llm_id, dialogId, form]); const isLatestChat = idx === chatBoxIds.length - 1; @@ -176,6 +189,7 @@ const ChatCard = forwardRef(function ChatCard( params: { ...currentDialog, llm_id: llmId, + tenant_llm_id: llmId, llm_setting: { ...omit(values, 'llm_id'), model_type: findLlmByUuid(llmId)?.model_type || 'chat',