@@ -321,6 +321,12 @@ interface MessagesTimelineProps {
321321 runningTurnId : TurnId | null ;
322322 turnDiffSummaries : ReadonlyArray < TurnDiffSummary > ;
323323 routeThreadKey : string ;
324+ /**
325+ * Thread whose entries are currently painted. Differs from `routeThreadKey`
326+ * while a jump is still holding the previous list. Identity for row
327+ * projection and list extraData — do not remount on this value.
328+ */
329+ displayThreadKey ?: string ;
324330 onOpenTurnDiff : ( turnId : TurnId , filePath ?: string ) => void ;
325331 supportsConversationRollback : boolean ;
326332 onRevertToTurnCount : ( targetTurnCount : number ) => void ;
@@ -379,6 +385,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
379385 runningTurnId,
380386 turnDiffSummaries,
381387 routeThreadKey,
388+ displayThreadKey,
382389 onOpenTurnDiff,
383390 supportsConversationRollback,
384391 onRevertToTurnCount,
@@ -406,17 +413,30 @@ export const MessagesTimeline = memo(function MessagesTimeline({
406413 loadEarlier = null ,
407414} : MessagesTimelineProps ) {
408415 const [ expandedTurnIds , setExpandedTurnIds ] = useState < ReadonlySet < TurnId > > ( new Set ( ) ) ;
416+ const [ expandedWorkGroupIds , setExpandedWorkGroupIds ] = useState < ReadonlySet < string > > ( new Set ( ) ) ;
417+ const listIdentityKey = displayThreadKey ?? routeThreadKey ;
418+ const listIdentityRef = useRef ( listIdentityKey ) ;
419+ const previousLatestTurnRef = useRef ( latestTurn ) ;
420+ let paintedExpandedTurnIds = expandedTurnIds ;
421+ let paintedExpandedWorkGroupIds = expandedWorkGroupIds ;
422+ if ( listIdentityRef . current !== listIdentityKey ) {
423+ listIdentityRef . current = listIdentityKey ;
424+ previousLatestTurnRef . current = latestTurn ;
425+ paintedExpandedTurnIds = new Set ( ) ;
426+ paintedExpandedWorkGroupIds = new Set ( ) ;
427+ setExpandedTurnIds ( paintedExpandedTurnIds ) ;
428+ setExpandedWorkGroupIds ( paintedExpandedWorkGroupIds ) ;
429+ }
409430 const citationThreadRef = useMemo ( ( ) => parseScopedThreadKey ( routeThreadKey ) , [ routeThreadKey ] ) ;
410431 const expandCitedTurn = useCallback ( ( turnId : TurnId ) => {
411432 setExpandedTurnIds ( ( current ) =>
412433 current . has ( turnId ) ? current : new Set ( [ ...current , turnId ] ) ,
413434 ) ;
414435 } , [ ] ) ;
415- const [ expandedWorkGroupIds , setExpandedWorkGroupIds ] = useState < ReadonlySet < string > > ( new Set ( ) ) ;
416436 // Scroll/disclosure state outlives virtualized rows, but never the current thread.
417437 const workGroupViewState = useMemo < WorkGroupViewState > (
418438 ( ) => ( { scrollPositions : new Map ( ) , expandedEntries : new Set ( ) } ) ,
419- [ routeThreadKey ] ,
439+ [ listIdentityKey ] ,
420440 ) ;
421441 const [ disclosureToggleSettling , setDisclosureToggleSettling ] = useState ( false ) ;
422442 const [ minimapStripMap ] = useState ( ( ) => new Map < string , HTMLSpanElement > ( ) ) ;
@@ -508,7 +528,6 @@ export const MessagesTimeline = memo(function MessagesTimeline({
508528
509529 // An in-session interrupt leaves its turn expanded so the user keeps their
510530 // place; the next turn (or a reload, since this is local state) folds it.
511- const previousLatestTurnRef = useRef ( latestTurn ) ;
512531 useEffect ( ( ) => {
513532 const previous = previousLatestTurnRef . current ;
514533 previousLatestTurnRef . current = latestTurn ;
@@ -547,34 +566,34 @@ export const MessagesTimeline = memo(function MessagesTimeline({
547566 timelineEntries,
548567 latestTurn,
549568 runningTurnId,
550- expandedTurnIds,
551- expandedWorkGroupIds,
569+ expandedTurnIds : paintedExpandedTurnIds ,
570+ expandedWorkGroupIds : paintedExpandedWorkGroupIds ,
552571 isWorking,
553572 activeTurnStartedAt,
554573 turnDiffSummaries,
555574 supportsConversationRollback,
556575 } ,
557- previous ?. threadKey === routeThreadKey && previous . workspaceRoot === workspaceRoot
576+ previous ?. threadKey === listIdentityKey && previous . workspaceRoot === workspaceRoot
558577 ? previous . projection
559578 : null ,
560579 ) ;
561- rowsProjectionRef . current = { threadKey : routeThreadKey , workspaceRoot, projection } ;
580+ rowsProjectionRef . current = { threadKey : listIdentityKey , workspaceRoot, projection } ;
562581 return projection . rows ;
563582 } , [
564583 rowsProjectionRef ,
565- routeThreadKey ,
584+ listIdentityKey ,
566585 workspaceRoot ,
567586 timelineEntries ,
568587 latestTurn ,
569588 runningTurnId ,
570- expandedTurnIds ,
571- expandedWorkGroupIds ,
589+ paintedExpandedTurnIds ,
590+ paintedExpandedWorkGroupIds ,
572591 isWorking ,
573592 activeTurnStartedAt ,
574593 turnDiffSummaries ,
575594 supportsConversationRollback ,
576595 ] ) ;
577- const rows = useStableRows ( rawRows ) ;
596+ const rows = useStableRows ( rawRows , listIdentityKey ) ;
578597 const minimapItems = useMemo ( ( ) => deriveTimelineMinimapItems ( rows ) , [ rows ] ) ;
579598 const [ timelineViewportElement , setTimelineViewportElement ] = useState < HTMLDivElement | null > (
580599 null ,
@@ -841,7 +860,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
841860 < LegendList < MessagesTimelineRow >
842861 ref = { listRef }
843862 data = { rows }
844- extraData = { rows . length }
863+ extraData = { ` ${ listIdentityKey } : ${ rows . length } ` }
845864 keyExtractor = { keyExtractor }
846865 getItemType = { getItemType }
847866 renderItem = { renderItem }
@@ -2762,17 +2781,23 @@ function UserMessageReviewCommentCard({ comment }: { comment: ReviewCommentConte
27622781
27632782/** Returns a structurally-shared copy of `rows`: for each row whose content
27642783 * hasn't changed since last call, the previous object reference is reused. */
2765- function useStableRows ( rows : MessagesTimelineRow [ ] ) : MessagesTimelineRow [ ] {
2784+ function useStableRows ( rows : MessagesTimelineRow [ ] , identity : string ) : MessagesTimelineRow [ ] {
27662785 const prevState = useRef < StableMessagesTimelineRowsState > ( {
27672786 byId : new Map < string , MessagesTimelineRow > ( ) ,
27682787 result : [ ] ,
27692788 } ) ;
2789+ const prevIdentity = useRef ( identity ) ;
27702790
27712791 return useMemo ( ( ) => {
2772- const nextState = computeStableMessagesTimelineRows ( rows , prevState . current ) ;
2792+ const previous =
2793+ prevIdentity . current === identity
2794+ ? prevState . current
2795+ : { byId : new Map < string , MessagesTimelineRow > ( ) , result : [ ] } ;
2796+ prevIdentity . current = identity ;
2797+ const nextState = computeStableMessagesTimelineRows ( rows , previous ) ;
27732798 prevState . current = nextState ;
27742799 return nextState . result ;
2775- } , [ rows ] ) ;
2800+ } , [ identity , rows ] ) ;
27762801}
27772802
27782803// ---------------------------------------------------------------------------
0 commit comments