From 246bd80ffe2e040d73d010156bda9161e9ac9fc4 Mon Sep 17 00:00:00 2001 From: Innei Date: Sat, 18 Oct 2025 20:59:11 +0800 Subject: [PATCH] fix: ai chain thought close state - Replaced the random ID generation for collapseId with React's useId for improved stability and performance. - Updated the effect logic to conditionally close the collapse based on the currentChainReasoningIsFinished state. Signed-off-by: Innei --- .../modules/ai-chat/components/displays/AIChainOfThought.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIChainOfThought.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIChainOfThought.tsx index a1e92615a..b127b18b0 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIChainOfThought.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIChainOfThought.tsx @@ -20,7 +20,7 @@ interface AIChainOfThoughtProps { } export const AIChainOfThought: React.FC = React.memo( ({ groups, isStreaming, className }) => { - const collapseId = React.useMemo(() => `chain-${Math.random().toString(36).slice(2)}`, []) + const collapseId = React.useId() const collapseRef = React.useRef(null) @@ -58,7 +58,7 @@ export const AIChainOfThought: React.FC = React.memo( }, [groups, isStreaming]) React.useEffect(() => { - collapseRef.current?.setIsOpened(!currentChainReasoningIsFinished) + if (currentChainReasoningIsFinished) collapseRef.current?.setIsOpened(false) }, [collapseRef, currentChainReasoningIsFinished]) if (!groups || groups.length === 0) return null