@@ -335,12 +335,14 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
335
335
336
336
const [ autoscrollToRecent , setAutoscrollToRecent ] = useState ( false ) ;
337
337
338
+ const minIndexForVisible = Math . min ( 1 , processedMessageList . length ) ;
339
+
338
340
const maintainVisibleContentPosition = useMemo (
339
341
( ) => ( {
340
342
autoscrollToTopThreshold : autoscrollToRecent ? 10 : undefined ,
341
- minIndexForVisible : 1 ,
343
+ minIndexForVisible,
342
344
} ) ,
343
- [ autoscrollToRecent ] ,
345
+ [ autoscrollToRecent , minIndexForVisible ] ,
344
346
) ;
345
347
346
348
/**
@@ -620,7 +622,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
620
622
} , [ threadList , messageListLengthAfterUpdate , topMessageAfterUpdate ?. id ] ) ;
621
623
622
624
useEffect ( ( ) => {
623
- if ( ! rawMessageList . length ) {
625
+ if ( ! processedMessageList . length ) {
624
626
return ;
625
627
}
626
628
if ( threadList ) {
@@ -637,7 +639,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
637
639
}
638
640
const latestNonCurrentMessageBeforeUpdate = latestNonCurrentMessageBeforeUpdateRef . current ;
639
641
latestNonCurrentMessageBeforeUpdateRef . current = undefined ;
640
- const latestCurrentMessageAfterUpdate = rawMessageList [ rawMessageList . length - 1 ] ;
642
+ const latestCurrentMessageAfterUpdate = processedMessageList [ 0 ] ;
641
643
if ( ! latestCurrentMessageAfterUpdate ) {
642
644
setAutoscrollToRecent ( true ) ;
643
645
return ;
@@ -662,7 +664,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
662
664
}
663
665
}
664
666
// eslint-disable-next-line react-hooks/exhaustive-deps
665
- } , [ channel , rawMessageList , threadList ] ) ;
667
+ } , [ channel , processedMessageList , threadList ] ) ;
666
668
667
669
const goToMessage = useStableCallback ( async ( messageId : string ) => {
668
670
const indexOfParentInMessageList = processedMessageList . findIndex (
0 commit comments