@@ -465,7 +465,6 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
465465 }
466466 } , [ ] )
467467
468-
469468 useEffect ( ( ) => {
470469 const prev = prevExpandedRowsRef . current
471470 let wasAnyRowExpandedByUser = false
@@ -964,24 +963,24 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
964963
965964 return newVisibleMessages
966965 } , [ modifiedMessages ] )
967-
966+
968967 useEffect ( ( ) => {
969968 const cleanupInterval = setInterval ( ( ) => {
970969 const cache = everVisibleMessagesTsRef . current
971970 const currentMessageIds = new Set ( modifiedMessages . map ( ( m : ClineMessage ) => m . ts ) )
972971 const viewportMessages = visibleMessages . slice ( Math . max ( 0 , visibleMessages . length - 100 ) )
973972 const viewportMessageIds = new Set ( viewportMessages . map ( ( m : ClineMessage ) => m . ts ) )
974-
973+
975974 cache . forEach ( ( _value : boolean , key : number ) => {
976975 if ( ! currentMessageIds . has ( key ) && ! viewportMessageIds . has ( key ) ) {
977976 cache . delete ( key )
978977 }
979978 } )
980979 } , 60000 )
981-
980+
982981 return ( ) => clearInterval ( cleanupInterval )
983982 } , [ modifiedMessages , visibleMessages ] )
984-
983+
985984 useDebounceEffect (
986985 ( ) => {
987986 if ( ! isHidden && ! sendingDisabled && ! enableButtons ) {
@@ -1337,10 +1336,23 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
13371336
13381337 const scrollToBottomSmooth = useMemo (
13391338 ( ) =>
1340- debounce ( ( ) => virtuosoRef . current ?. scrollTo ( { top : Number . MAX_SAFE_INTEGER , behavior : "smooth" } ) , 10 , {
1341- immediate : true ,
1342- } ) ,
1343- [ ] ,
1339+ debounce (
1340+ ( ) => {
1341+ const lastIndex = groupedMessages . length - 1
1342+ if ( lastIndex >= 0 ) {
1343+ virtuosoRef . current ?. scrollToIndex ( {
1344+ index : lastIndex ,
1345+ behavior : "smooth" ,
1346+ align : "end" ,
1347+ } )
1348+ }
1349+ } ,
1350+ 10 ,
1351+ {
1352+ immediate : true ,
1353+ } ,
1354+ ) ,
1355+ [ groupedMessages . length ] ,
13441356 )
13451357
13461358 useEffect ( ( ) => {
@@ -1352,11 +1364,15 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
13521364 } , [ scrollToBottomSmooth ] )
13531365
13541366 const scrollToBottomAuto = useCallback ( ( ) => {
1355- virtuosoRef . current ?. scrollTo ( {
1356- top : Number . MAX_SAFE_INTEGER ,
1357- behavior : "auto" , // Instant causes crash.
1358- } )
1359- } , [ ] )
1367+ const lastIndex = groupedMessages . length - 1
1368+ if ( lastIndex >= 0 ) {
1369+ virtuosoRef . current ?. scrollToIndex ( {
1370+ index : lastIndex ,
1371+ behavior : "auto" , // Instant causes crash.
1372+ align : "end" ,
1373+ } )
1374+ }
1375+ } , [ groupedMessages . length ] )
13601376
13611377 const handleSetExpandedRow = useCallback (
13621378 ( ts : number , expand ?: boolean ) => {
0 commit comments