@@ -9,6 +9,14 @@ import { vscode } from "@src/utils/vscode"
99
1010import ChatView , { ChatViewProps } from "../ChatView"
1111
12+ const mockVirtuosoState = vi . hoisted ( ( ) => ( {
13+ lastConfig : null as {
14+ computeItemKey ?: ( index : number , item : ClineMessage ) => React . Key
15+ defaultItemHeight ?: number
16+ increaseViewportBy ?: number | { top ?: number ; bottom ?: number }
17+ } | null ,
18+ } ) )
19+
1220// Define minimal types needed for testing
1321interface ClineMessage {
1422 type : "say" | "ask"
@@ -61,14 +69,26 @@ vi.mock("react-virtuoso", () => ({
6169 Virtuoso : function MockVirtuoso ( {
6270 data,
6371 itemContent,
72+ computeItemKey,
73+ defaultItemHeight,
74+ increaseViewportBy,
6475 } : {
6576 data : ClineMessage [ ]
6677 itemContent : ( index : number , item : ClineMessage ) => React . ReactNode
78+ computeItemKey ?: ( index : number , item : ClineMessage ) => React . Key
79+ defaultItemHeight ?: number
80+ increaseViewportBy ?: number | { top ?: number ; bottom ?: number }
6781 } ) {
82+ mockVirtuosoState . lastConfig = {
83+ computeItemKey,
84+ defaultItemHeight,
85+ increaseViewportBy,
86+ }
87+
6888 return (
6989 < div data-testid = "virtuoso-item-list" >
7090 { data . map ( ( item , index ) => (
71- < div key = { item . ts } data-testid = { `virtuoso-item-${ index } ` } >
91+ < div key = { computeItemKey ?. ( index , item ) ?? item . ts } data-testid = { `virtuoso-item-${ index } ` } >
7292 { itemContent ( index , item ) }
7393 </ div >
7494 ) ) }
@@ -454,6 +474,45 @@ describe("ChatView - Sound Playing Tests", () => {
454474 } )
455475} )
456476
477+ describe ( "ChatView - Virtualization Configuration" , ( ) => {
478+ beforeEach ( ( ) => {
479+ vi . clearAllMocks ( )
480+ mockVirtuosoState . lastConfig = null
481+ } )
482+
483+ it ( "keeps the off-screen render buffer tight for chat rows" , async ( ) => {
484+ renderChatView ( )
485+
486+ const taskTs = Date . now ( ) - 100
487+ const rowTs = Date . now ( )
488+
489+ mockPostMessage ( {
490+ clineMessages : [
491+ {
492+ type : "say" ,
493+ say : "task" ,
494+ ts : taskTs ,
495+ text : "Initial task" ,
496+ } ,
497+ {
498+ type : "say" ,
499+ say : "text" ,
500+ ts : rowTs ,
501+ text : "Visible row" ,
502+ } ,
503+ ] ,
504+ } )
505+
506+ await waitFor ( ( ) => {
507+ expect ( mockVirtuosoState . lastConfig ) . not . toBeNull ( )
508+ } )
509+
510+ expect ( mockVirtuosoState . lastConfig ?. defaultItemHeight ) . toBe ( 180 )
511+ expect ( mockVirtuosoState . lastConfig ?. increaseViewportBy ) . toEqual ( { top : 600 , bottom : 800 } )
512+ expect ( mockVirtuosoState . lastConfig ?. computeItemKey ?.( 1 , { type : "say" , ts : rowTs } ) ) . toBe ( rowTs )
513+ } )
514+ } )
515+
457516describe ( "ChatView - Focus Grabbing Tests" , ( ) => {
458517 beforeEach ( ( ) => vi . clearAllMocks ( ) )
459518
0 commit comments