@@ -659,12 +659,11 @@ const ConversationTimeline = memo(function ConversationTimeline({
659659 ? new Set ( paintedExpandedAttemptIds ) . add ( activeFindAttemptId )
660660 : paintedExpandedAttemptIds ;
661661
662- const pendingApprovalsByRequestId = new Map (
663- pendingApprovals
664- . filter ( ( approval ) => ! heldApprovalRequestIds ?. has ( approval . requestId ) )
665- . map ( ( approval ) => [ approval . requestId , approval ] ) ,
662+ const isVisiblePendingApproval = ( approval : PendingApproval ) =>
663+ ! heldApprovalRequestIds ?. has ( approval . requestId ) ;
664+ const pendingApprovalRequestIds = new Set (
665+ pendingApprovals . filter ( isVisiblePendingApproval ) . map ( ( approval ) => approval . requestId ) ,
666666 ) ;
667- const pendingApprovalRequestIds = new Set ( pendingApprovalsByRequestId . keys ( ) ) ;
668667 const rawRows = useIncrementalTimelineRows ( `${ listIdentityKey } \0${ workspaceRoot ?? "" } ` , {
669668 timelineEntries,
670669 pendingApprovalRequestIds,
@@ -683,17 +682,19 @@ const ConversationTimeline = memo(function ConversationTimeline({
683682 worktreeSetup,
684683 } ) ;
685684 const rows = useStableRows ( rawRows , listIdentityKey ) ;
686- const unmatchedPendingApprovals = new Map ( pendingApprovalsByRequestId ) ;
687- if ( unmatchedPendingApprovals . size > 0 ) {
688- for ( const row of rows ) {
689- const entries =
690- row . kind === "work" ? row . groupedEntries : row . kind === "work-live" ? [ row . entry ] : [ ] ;
691- for ( const entry of entries ) {
692- const item = entry . projectedItem ?. item ;
693- if ( item ?. type === "approval_request" ) unmatchedPendingApprovals . delete ( item . requestId ) ;
694- }
685+ const matchedApprovalRequestIds = new Set < string > ( ) ;
686+ for ( const row of pendingApprovalRequestIds . size > 0 ? rows : [ ] ) {
687+ const entries =
688+ row . kind === "work" ? row . groupedEntries : row . kind === "work-live" ? [ row . entry ] : [ ] ;
689+ for ( const entry of entries ) {
690+ const item = entry . projectedItem ?. item ;
691+ if ( item ?. type === "approval_request" ) matchedApprovalRequestIds . add ( item . requestId ) ;
695692 }
696693 }
694+ const unmatchedPendingApprovals = pendingApprovals . filter (
695+ ( approval ) =>
696+ isVisiblePendingApproval ( approval ) && ! matchedApprovalRequestIds . has ( approval . requestId ) ,
697+ ) ;
697698 // Run status/timestamps change per stream event; keep them out of shared row context.
698699 const runs = useStableHandoffRuns ( runsProp ) ;
699700 const minimapItems = deriveTimelineMinimapItems ( rows ) ;
@@ -706,7 +707,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
706707 restoringThreadPosition && restoreRowIndex >= 0 ? { indices : [ restoreRowIndex ] } : undefined ;
707708 const showsEmptyState =
708709 rows . length === 0 &&
709- unmatchedPendingApprovals . size === 0 &&
710+ unmatchedPendingApprovals . length === 0 &&
710711 ! isWorking &&
711712 parentThreadLink === null &&
712713 historyControls === undefined &&
@@ -1000,6 +1001,13 @@ const ConversationTimeline = memo(function ConversationTimeline({
10001001 } ;
10011002 } ;
10021003
1004+ // Built from props after the last hook so the compiler can memoize the row context; a map
1005+ // made before a hook would rebuild it, and re-render every row, on each streamed update.
1006+ const pendingApprovalsByRequestId = new Map (
1007+ pendingApprovals
1008+ . filter ( isVisiblePendingApproval )
1009+ . map ( ( approval ) => [ approval . requestId , approval ] ) ,
1010+ ) ;
10031011 const sharedState : TimelineRowSharedState = {
10041012 pendingApprovals : pendingApprovalsByRequestId ,
10051013 respondingRequestIds,
@@ -1238,12 +1246,12 @@ const ConversationTimeline = memo(function ConversationTimeline({
12381246 onGrow = { onFooterGrow }
12391247 >
12401248 { footer }
1241- { unmatchedPendingApprovals . size > 0 ? (
1249+ { unmatchedPendingApprovals . length > 0 ? (
12421250 < TimelineRowCtx value = { sharedState } >
12431251 < div className = "messages-timeline-row-frame" >
12441252 < div className = "chat-content-lane overflow-x-clip" data-timeline-root = "true" >
12451253 < WorkLogBlock >
1246- { [ ... unmatchedPendingApprovals . values ( ) ] . map ( ( approval ) => (
1254+ { unmatchedPendingApprovals . map ( ( approval ) => (
12471255 < TimelinePendingApprovalRow key = { approval . requestId } approval = { approval } />
12481256 ) ) }
12491257 </ WorkLogBlock >
0 commit comments