fix(ui): keep completed reasoning collapsed

This commit is contained in:
Bohdan Triapitsyn
2026-05-21 15:45:44 +03:00
parent b523dcae91
commit 40210917c2
@@ -89,12 +89,14 @@ export const ReasoningTimelineBlock: React.FC<ReasoningTimelineBlockProps> = ({
variant, variant,
onContentChange, onContentChange,
blockId, blockId,
time,
isStreaming = false, isStreaming = false,
actions, actions,
defaultExpanded, defaultExpanded,
}) => { }) => {
const { t } = useI18n(); const { t } = useI18n();
const [isExpanded, setIsExpanded] = React.useState(defaultExpanded ?? isStreaming); const hasEnded = typeof time?.end === 'number';
const [isExpanded, setIsExpanded] = React.useState(hasEnded ? false : (defaultExpanded ?? isStreaming));
const contentId = React.useId(); const contentId = React.useId();
const scrollRef = React.useRef<HTMLElement>(null); const scrollRef = React.useRef<HTMLElement>(null);
const contentRef = React.useRef<HTMLDivElement>(null); const contentRef = React.useRef<HTMLDivElement>(null);
@@ -126,10 +128,10 @@ export const ReasoningTimelineBlock: React.FC<ReasoningTimelineBlockProps> = ({
prevIsStreamingRef.current = isStreaming; prevIsStreamingRef.current = isStreaming;
// Auto-collapse only when streaming ends (true → false). // Auto-collapse only when streaming ends (true → false).
// Do not fire on mount so that defaultExpanded is respected. // Do not fire on mount so that defaultExpanded is respected.
if (wasStreaming && !isStreaming) { if (hasEnded || (wasStreaming && !isStreaming)) {
setIsExpanded(false); setIsExpanded(false);
} }
}, [isStreaming]); }, [hasEnded, isStreaming]);
React.useEffect(() => { React.useEffect(() => {
if (text.trim().length === 0) { if (text.trim().length === 0) {