diff --git a/web/app/components/base/markdown-blocks/__tests__/think-block.spec.tsx b/web/app/components/base/markdown-blocks/__tests__/think-block.spec.tsx index e8b956cbbf..4f22468157 100644 --- a/web/app/components/base/markdown-blocks/__tests__/think-block.spec.tsx +++ b/web/app/components/base/markdown-blocks/__tests__/think-block.spec.tsx @@ -163,25 +163,16 @@ describe('ThinkBlock', () => { expect(screen.getByText(/Thought/)).toBeInTheDocument() }) - it('should NOT stop timer when isResponding is undefined (outside ChatContextProvider)', () => { - // Render without ChatContextProvider + it('should stop timer when isResponding is undefined (historical conversation outside active response)', () => { + // Render without ChatContextProvider — simulates historical conversation render(

Content without ENDTHINKFLAG

, ) - // Initial state should show "Thinking..." - expect(screen.getByText(/Thinking\.\.\./)).toBeInTheDocument() - - // Advance timer - act(() => { - vi.advanceTimersByTime(2000) - }) - - // Timer should still be running (showing "Thinking..." not "Thought") - expect(screen.getByText(/Thinking\.\.\./)).toBeInTheDocument() - expect(screen.getByText(/\(2\.0s\)/)).toBeInTheDocument() + // Timer should be stopped immediately — isResponding undefined means not in active response + expect(screen.getByText(/Thought/)).toBeInTheDocument() }) }) diff --git a/web/app/components/base/markdown-blocks/think-block.tsx b/web/app/components/base/markdown-blocks/think-block.tsx index f920218152..184ed89274 100644 --- a/web/app/components/base/markdown-blocks/think-block.tsx +++ b/web/app/components/base/markdown-blocks/think-block.tsx @@ -39,9 +39,10 @@ const removeEndThink = (children: any): any => { const useThinkTimer = (children: any) => { const { isResponding } = useChatContext() + const endThinkDetected = hasEndThink(children) const [startTime] = useState(() => Date.now()) const [elapsedTime, setElapsedTime] = useState(0) - const [isComplete, setIsComplete] = useState(false) + const [isComplete, setIsComplete] = useState(() => endThinkDetected) const timerRef = useRef(null) useEffect(() => { @@ -61,11 +62,10 @@ const useThinkTimer = (children: any) => { useEffect(() => { // Stop timer when: // 1. Content has [ENDTHINKFLAG] marker (normal completion) - // 2. isResponding is explicitly false (user clicked stop button) - // Note: Don't stop when isResponding is undefined (component used outside ChatContextProvider) - if (hasEndThink(children) || isResponding === false) + // 2. isResponding is not true (false = user clicked stop, undefined = historical conversation) + if (endThinkDetected || !isResponding) setIsComplete(true) - }, [children, isResponding]) + }, [endThinkDetected, isResponding]) return { elapsedTime, isComplete } }