Skip to content

Commit 01ed9cc

Browse files
committed
fix: resolve scroll jumping issue on smaller screens
- Increased message limit threshold from 500 to 750 messages - Only apply message limiting for very long conversations (>1000 messages) - Balanced viewport rendering (1500px top/bottom instead of 3000px/1000px) - Increased LRU cache capacity from 100 to 200 entries with longer TTL - Expanded viewport tracking window from 100 to 200 messages These changes prevent aggressive message filtering that was causing scroll position jumps while maintaining memory optimizations from PR #6697. Fixes #7026
1 parent 7b0f489 commit 01ed9cc

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
181181
const [showAnnouncementModal, setShowAnnouncementModal] = useState(false)
182182
const everVisibleMessagesTsRef = useRef<LRUCache<number, boolean>>(
183183
new LRUCache({
184-
max: 100,
185-
ttl: 1000 * 60 * 5,
184+
max: 200,
185+
ttl: 1000 * 60 * 10,
186186
}),
187187
)
188188
const autoApproveTimeoutRef = useRef<NodeJS.Timeout | null>(null)
@@ -897,11 +897,14 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
897897
useMount(() => textAreaRef.current?.focus())
898898

899899
const visibleMessages = useMemo(() => {
900+
// Use a more conservative approach for message filtering to prevent jumping
901+
// Only apply the 500 message limit for very long conversations
900902
const currentMessageCount = modifiedMessages.length
901-
const startIndex = Math.max(0, currentMessageCount - 500)
902-
const recentMessages = modifiedMessages.slice(startIndex)
903+
const shouldLimitMessages = currentMessageCount > 1000
904+
const startIndex = shouldLimitMessages ? Math.max(0, currentMessageCount - 750) : 0
905+
const messagesToProcess = modifiedMessages.slice(startIndex)
903906

904-
const newVisibleMessages = recentMessages.filter((message: ClineMessage) => {
907+
const newVisibleMessages = messagesToProcess.filter((message: ClineMessage) => {
905908
if (everVisibleMessagesTsRef.current.has(message.ts)) {
906909
const alwaysHiddenOnceProcessedAsk: ClineAsk[] = [
907910
"api_req_failed",
@@ -954,7 +957,10 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
954957
return true
955958
})
956959

957-
const viewportStart = Math.max(0, newVisibleMessages.length - 100)
960+
// Track visible messages more conservatively to avoid cache thrashing
961+
// Only track messages that are actually in the current viewport
962+
const viewportWindow = Math.min(200, newVisibleMessages.length)
963+
const viewportStart = Math.max(0, newVisibleMessages.length - viewportWindow)
958964
newVisibleMessages
959965
.slice(viewportStart)
960966
.forEach((msg: ClineMessage) => everVisibleMessagesTsRef.current.set(msg.ts, true))
@@ -1870,7 +1876,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
18701876
ref={virtuosoRef}
18711877
key={task.ts}
18721878
className="scrollable grow overflow-y-scroll mb-1"
1873-
increaseViewportBy={{ top: 3_000, bottom: 1000 }}
1879+
increaseViewportBy={{ top: 1500, bottom: 1500 }}
18741880
data={groupedMessages}
18751881
itemContent={itemContent}
18761882
atBottomStateChange={(isAtBottom: boolean) => {

0 commit comments

Comments
 (0)