@@ -1221,6 +1221,55 @@ describe("MessagesTimeline thread find", () => {
12211221 expect ( top ) . toBeLessThan ( bounds . bottom ) ;
12221222 } ) ;
12231223 } ) ;
1224+
1225+ it ( "lets go of a timeline once find has no match in it" , async ( ) => {
1226+ setup ( ) ;
1227+ const base = baseProps ( ) ;
1228+ await using screen = await renderElement (
1229+ < MessagesTimeline { ...base } timelineEntries = { [ message ( "Short thread" ) ] } /> ,
1230+ ) ;
1231+ // In its own function, so nothing in this test's frame holds the entries after the switch.
1232+ const revealMatch = async ( ) => {
1233+ const replies = Array . from ( { length : 40 } , ( _ , index ) =>
1234+ message (
1235+ `${ index === 5 ? "Needle here" : `Reply ${ index } ` } \n\n${ "line\n\n" . repeat ( 8 ) } ` ,
1236+ { role : "assistant" } ,
1237+ `r-${ index } ` ,
1238+ ) ,
1239+ ) ;
1240+ await screen . rerender (
1241+ < MessagesTimeline
1242+ { ...base }
1243+ routeThreadKey = "environment-local:thread-find-left"
1244+ timelineEntries = { replies }
1245+ liveFollowEnabled = { false }
1246+ findOpen
1247+ findExpanded
1248+ findQuery = "Needle"
1249+ activeFindMatch = { { entryId : "entry-r-5" , runId : null , occurrence : 0 } }
1250+ /> ,
1251+ ) ;
1252+ const viewport = base . listRef . current ! . getScrollableNode ( ) ! ;
1253+ await vi . waitFor ( ( ) => {
1254+ const row = screen . container . querySelector ( '[data-timeline-row-id="entry-r-5"]' ) ;
1255+ expect ( row ) . not . toBeNull ( ) ;
1256+ const bounds = viewport . getBoundingClientRect ( ) ;
1257+ const top = row ! . getBoundingClientRect ( ) . top ;
1258+ expect ( top ) . toBeGreaterThanOrEqual ( bounds . top ) ;
1259+ expect ( top ) . toBeLessThan ( bounds . bottom ) ;
1260+ } ) ;
1261+ return new WeakRef ( replies ) ;
1262+ } ;
1263+ const shown = await revealMatch ( ) ;
1264+
1265+ // Twice, because React keeps the previous render's props until the next render.
1266+ for ( const text of [ "Another thread" , "Another thread, updated" ] ) {
1267+ await screen . rerender ( < MessagesTimeline { ...base } timelineEntries = { [ message ( text ) ] } /> ) ;
1268+ }
1269+ await cdp ( ) . send ( "HeapProfiler.collectGarbage" ) ;
1270+
1271+ expect ( shown . deref ( ) ) . toBeUndefined ( ) ;
1272+ } ) ;
12241273} ) ;
12251274
12261275describe ( "compact reasoning math" , ( ) => {
0 commit comments