From a897a25aa75fd377b6e47b55ac52f20ed36f8343 Mon Sep 17 00:00:00 2001 From: balibabu Date: Fri, 14 Aug 2026 20:18:55 +0800 Subject: [PATCH] Fix:The dialog will display the referenced documentation even if the API does not return any documentation data. (#18298) --- web/src/pages/next-chats/chat/index.tsx | 51 +++++++++++-------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/web/src/pages/next-chats/chat/index.tsx b/web/src/pages/next-chats/chat/index.tsx index 1f8602fd3b..eab833464b 100644 --- a/web/src/pages/next-chats/chat/index.tsx +++ b/web/src/pages/next-chats/chat/index.tsx @@ -8,10 +8,9 @@ import { import { IClientConversation } from '@/interfaces/database/chat'; import { RootLayoutContainer } from '@/layouts/root-layout'; import { cn } from '@/lib/utils'; -import { useMount } from 'ahooks'; import { isEmpty } from 'lodash'; import { LucideArrowBigLeft, LucideArrowUpRight } from 'lucide-react'; -import { useCallback, useMemo, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useHandleClickConversationCard } from '../hooks/use-click-card'; import { ChatSettings } from './app-settings/chat-settings'; @@ -46,32 +45,26 @@ export default function Chat() { ); }, [conversationId, dialogList, t]); - const fetchConversation: typeof handleConversationCardClick = useCallback( - async (conversationId, isNew) => { - if (conversationId && !isNew) { - const conversation = await fetchSessionManually(conversationId); - if (!isEmpty(conversation)) { - setCurrentConversation(conversation); - } - } else { - // New session: clear previous session's messages so they don't leak in. - setCurrentConversation({} as IClientConversation); + // The URL is the single source of truth for which conversation is open: + // card clicks, "+" and the temp→real id swap after the first send all land + // here. Clear first so the previous conversation's messages and references + // can never leak into the newly opened one while the fetch is in flight. + useEffect(() => { + setCurrentConversation((previous) => + isEmpty(previous) ? previous : ({} as IClientConversation), + ); + if (!conversationId || isNew === 'true') return; + + let cancelled = false; + fetchSessionManually(conversationId).then((conversation) => { + if (!cancelled && !isEmpty(conversation)) { + setCurrentConversation(conversation); } - }, - [fetchSessionManually], - ); - - const handleSessionClick: typeof handleConversationCardClick = useCallback( - (conversationId, isNew) => { - handleConversationCardClick(conversationId, isNew); - fetchConversation(conversationId, isNew); - }, - [fetchConversation, handleConversationCardClick], - ); - - useMount(() => { - fetchConversation(conversationId, isNew === 'true'); - }); + }); + return () => { + cancelled = true; + }; + }, [conversationId, isNew, fetchSessionManually]); if (isDebugMode) { return ( @@ -112,7 +105,9 @@ export default function Chat() {
- +