@@ -1105,38 +1105,9 @@ const ConversationTimeline = memo(function ConversationTimeline({
11051105 // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Added or removed rows change the content height.
11061106 } , [ cancelContentOverflowFrame , measureContentOverflow , onContentOverflowChange , rows . length ] ) ;
11071107
1108- const handleScroll = ( ) => {
1108+ const refreshMinimap = useStableCallback ( ( ) => {
11091109 const state = listRef . current ?. getState ?.( ) ;
11101110 if ( restoringThreadPosition || state ?. data !== rows ) return ;
1111- const isAtEnd = resolveTimelineIsAtEnd ( state ) ;
1112- const position = state ?. data ?. length ? resolveWorkGroupScrollAnchor ( state ) : undefined ;
1113- if ( position && state && isAtEnd !== undefined && ! paintOnly ) {
1114- const index = state . indexByKey ( position . rowId ) ;
1115- const row = index === undefined ? undefined : state . elementAtIndex ( index ) ;
1116- const element = listRef . current ?. getScrollableNode ( ) ;
1117- if ( row && element ) {
1118- rememberTimelinePosition (
1119- listIdentityKey ,
1120- {
1121- ...position ,
1122- offsetWithinRow : element . getBoundingClientRect ( ) . top - row . getBoundingClientRect ( ) . top ,
1123- scrollOffset : element . scrollTop ,
1124- atEnd : isAtEnd ,
1125- disclosures : {
1126- runs : paintedExpandedRunIds ,
1127- workGroups : paintedExpandedWorkGroupIds ,
1128- attempts : paintedExpandedAttemptIds ,
1129- workGroupState : workGroupViewState ,
1130- } ,
1131- } ,
1132- liveFollowEnabled && ! anchoredEndSpace ,
1133- ) ;
1134- }
1135- }
1136- if ( isAtEnd !== undefined && ! citationPositioning ) {
1137- onIsAtEndChange ( isAtEnd ) ;
1138- }
1139- reportContentOverflow ( ) ;
11401111 if ( ! state || minimapItems . length === 0 ) {
11411112 return ;
11421113 }
@@ -1176,29 +1147,67 @@ const ConversationTimeline = memo(function ConversationTimeline({
11761147 setMinimapCurrentIndex ( ( current ) =>
11771148 current === nextCurrentIndex ? current : nextCurrentIndex ,
11781149 ) ;
1150+ } ) ;
1151+
1152+ const minimapRefreshFrameRef = useRef < number | null > ( null ) ;
1153+ const scheduleMinimapRefresh = ( ) => {
1154+ if ( minimapRefreshFrameRef . current !== null ) return ;
1155+ // LegendList recycles row containers before React commits their positions.
1156+ minimapRefreshFrameRef . current = requestAnimationFrame ( ( ) => {
1157+ minimapRefreshFrameRef . current = null ;
1158+ refreshMinimap ( ) ;
1159+ } ) ;
1160+ } ;
1161+
1162+ const handleScroll = ( ) => {
1163+ const state = listRef . current ?. getState ?.( ) ;
1164+ if ( restoringThreadPosition || state ?. data !== rows ) return ;
1165+ const isAtEnd = resolveTimelineIsAtEnd ( state ) ;
1166+ const position = state ?. data ?. length ? resolveWorkGroupScrollAnchor ( state ) : undefined ;
1167+ if ( position && state && isAtEnd !== undefined && ! paintOnly ) {
1168+ const index = state . indexByKey ( position . rowId ) ;
1169+ const row = index === undefined ? undefined : state . elementAtIndex ( index ) ;
1170+ const element = listRef . current ?. getScrollableNode ( ) ;
1171+ if ( row && element ) {
1172+ rememberTimelinePosition (
1173+ listIdentityKey ,
1174+ {
1175+ ...position ,
1176+ offsetWithinRow : element . getBoundingClientRect ( ) . top - row . getBoundingClientRect ( ) . top ,
1177+ scrollOffset : element . scrollTop ,
1178+ atEnd : isAtEnd ,
1179+ disclosures : {
1180+ runs : paintedExpandedRunIds ,
1181+ workGroups : paintedExpandedWorkGroupIds ,
1182+ attempts : paintedExpandedAttemptIds ,
1183+ workGroupState : workGroupViewState ,
1184+ } ,
1185+ } ,
1186+ liveFollowEnabled && ! anchoredEndSpace ,
1187+ ) ;
1188+ }
1189+ }
1190+ if ( isAtEnd !== undefined && ! citationPositioning ) {
1191+ onIsAtEndChange ( isAtEnd ) ;
1192+ }
1193+ reportContentOverflow ( ) ;
1194+ scheduleMinimapRefresh ( ) ;
11791195 } ;
11801196
1181- const refreshAfterMeasurement = useStableCallback ( handleScroll ) ;
1182- const itemMeasurementFrameRef = useRef < number | null > ( null ) ;
11831197 const handleItemSizeChanged = ( ) => {
11841198 if ( disclosurePinsEndRef . current ) {
11851199 queueMicrotask ( pinDisclosureToEnd ) ;
11861200 scheduleDisclosureSettle ( ) ;
11871201 }
11881202 reportContentOverflow ( ) ;
1189- if ( itemMeasurementFrameRef . current !== null ) return ;
1190- // Read after LegendList has applied all row measurements for this frame.
1191- itemMeasurementFrameRef . current = requestAnimationFrame ( ( ) => {
1192- itemMeasurementFrameRef . current = null ;
1193- refreshAfterMeasurement ( ) ;
1194- } ) ;
1203+ scheduleMinimapRefresh ( ) ;
11951204 } ;
11961205
11971206 useEffect (
11981207 ( ) => ( ) => {
1199- if ( itemMeasurementFrameRef . current !== null ) {
1200- cancelAnimationFrame ( itemMeasurementFrameRef . current ) ;
1201- itemMeasurementFrameRef . current = null ;
1208+ if ( minimapRefreshFrameRef . current !== null ) {
1209+ cancelAnimationFrame ( minimapRefreshFrameRef . current ) ;
1210+ minimapRefreshFrameRef . current = null ;
12021211 }
12031212 } ,
12041213 [ ] ,
0 commit comments