@@ -838,7 +838,7 @@ describe("MessagesTimeline history and thread links", () => {
838838 expect ( onOpenThread ) . toHaveBeenCalledWith ( "thread-parent" ) ;
839839 } ) ;
840840
841- it ( "opens a thread at its newest message after an empty pane" , async ( ) => {
841+ it ( "opens a thread at its newest message after an empty pane and restores it on return " , async ( ) => {
842842 const props = baseProps ( ) ;
843843 const entries = Array . from ( { length : 12 } , ( _ , index ) =>
844844 message (
@@ -865,6 +865,43 @@ describe("MessagesTimeline history and thread links", () => {
865865 viewport . scrollHeight - viewport . clientHeight - viewport . scrollTop ,
866866 ) . toBeLessThanOrEqual ( 1 ) ;
867867 } ) ;
868+
869+ const otherThreadKey = `${ props . routeThreadKey } -other` ;
870+ await act ( async ( ) =>
871+ roots
872+ . at ( - 1 ) !
873+ . render (
874+ < MessagesTimeline
875+ { ...props }
876+ routeThreadKey = { otherThreadKey }
877+ timelineEntries = { entries }
878+ liveFollowEnabled = { false }
879+ /> ,
880+ ) ,
881+ ) ;
882+ await vi . waitFor ( ( ) =>
883+ expect (
884+ viewport . scrollHeight - viewport . clientHeight - viewport . scrollTop ,
885+ ) . toBeLessThanOrEqual ( 1 ) ,
886+ ) ;
887+ // Move beyond LegendList's one-viewport follow threshold so it cannot mask restoration.
888+ await userEvent . wheel ( viewport , { delta : { y : - 2000 } } ) ;
889+ await vi . waitFor ( ( ) => {
890+ expect ( readTimelinePosition ( otherThreadKey ) ?. atEnd ) . toBe ( false ) ;
891+ expect ( viewport . scrollHeight - viewport . clientHeight - viewport . scrollTop ) . toBeGreaterThan (
892+ viewport . clientHeight ,
893+ ) ;
894+ } ) ;
895+
896+ await act ( async ( ) =>
897+ roots . at ( - 1 ) ! . render ( < MessagesTimeline { ...props } timelineEntries = { entries } /> ) ,
898+ ) ;
899+ await vi . waitFor ( ( ) => {
900+ expect ( text ( ) ) . toContain ( "Paragraph 11.59" ) ;
901+ expect (
902+ viewport . scrollHeight - viewport . clientHeight - viewport . scrollTop ,
903+ ) . toBeLessThanOrEqual ( 1 ) ;
904+ } ) ;
868905 } ) ;
869906
870907 it ( "does not render the transient V2 interruption request" , async ( ) => {
0 commit comments