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 <tukon479@gmail.com>
This commit is contained in:
Innei
2025-10-18 20:59:11 +08:00
parent 13147f5c43
commit 246bd80ffe
@@ -20,7 +20,7 @@ interface AIChainOfThoughtProps {
}
export const AIChainOfThought: React.FC<AIChainOfThoughtProps> = React.memo(
({ groups, isStreaming, className }) => {
const collapseId = React.useMemo(() => `chain-${Math.random().toString(36).slice(2)}`, [])
const collapseId = React.useId()
const collapseRef = React.useRef<CollapseCssRef>(null)
@@ -58,7 +58,7 @@ export const AIChainOfThought: React.FC<AIChainOfThoughtProps> = 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