Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions webview-ui/src/components/chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,23 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
}
}, [])

// Track if we're currently streaming a thinking/reasoning message
const isStreamingThinking = useMemo(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this thinking detection logic closer to where isStreaming is computed (around line 516) for better code organization. This would group related streaming logic together.

const lastMessage = modifiedMessages.at(-1)
return lastMessage?.say === "reasoning" && lastMessage?.partial === true
}, [modifiedMessages])

// Enhanced scroll behavior for thinking sections
useEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this new effect duplicates the scroll logic from lines 1399-1409. Both call scrollToBottomSmooth() under similar conditions. Could we consolidate these to avoid redundancy? Maybe combine the logic into the existing effect or extract a shared handler?

// When streaming thinking content, check if user has manually scrolled
// If they haven't, continue auto-scrolling
// If they have (disableAutoScrollRef.current is true), respect their choice
if (isStreamingThinking && !disableAutoScrollRef.current) {
// Continue auto-scrolling for thinking content if user hasn't intervened
scrollToBottomSmooth()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scrollToBottomSmooth cleanup at lines 1351-1357 might not properly cancel all pending debounce calls when isStreamingThinking changes rapidly. Should we ensure the cleanup is more comprehensive to prevent potential memory leaks?

}
}, [isStreamingThinking, scrollToBottomSmooth])

useEvent("wheel", handleWheel, window, { passive: true }) // passive improves scrolling performance

// Effect to handle showing the checkpoint warning after a delay
Expand Down Expand Up @@ -1903,6 +1920,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
atBottomStateChange={(isAtBottom: boolean) => {
setIsAtBottom(isAtBottom)
if (isAtBottom) {
// Re-enable autoscroll when user scrolls to bottom
// This is the key fix: users can scroll up to read thinking content,
// and autoscroll resumes when they scroll back down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is excellent! Consider adding a similar explanatory comment near the isStreamingThinking logic to explain why we need separate handling for thinking sections versus regular streaming content.

disableAutoScrollRef.current = false
}
setShowScrollToBottom(disableAutoScrollRef.current && !isAtBottom)
Expand Down
Loading