The best way to control Claude Code, Codex and more from any computer or phone
perf(web): switching threads no longer re-renders the outgoing thread's rows (#21123)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 18, 2026 at 02:12 UTC
91ec4bec2d3f6a9ace351f42e5bdf9f0a009d55a
1 file changed
+88
-82
apps/web/src/components/chat/MessagesTimeline.tsx
+88
-82
@@ -1374,13 +1374,21 @@ const ConversationTimeline = memo(function ConversationTimeline({
1374
contentInsetEndAdjustment,
1375
});
1376
1377
+ // Each row carries its own provider. LegendList moves rows into their
1378
+ // containers one commit after this component renders, so a provider around
1379
+ // the list would re-render the outgoing thread's rows with the incoming
1380
+ // thread's context just before they unmount. extraData hands a changed
1381
+ // sharedState to the rows that stay.
1382
const renderItem = ({ item }: { item: MessagesTimelineRow }) => (
1378
- <div className="messages-timeline-row-frame">
1379
- <div className="chat-content-lane overflow-x-clip" data-timeline-root="true">
1380
- <TimelineRowContent row={item} />
1383
+ <TimelineRowCtx value={sharedState}>
1384
+ <div className="messages-timeline-row-frame">
1385
+ <div className="chat-content-lane overflow-x-clip" data-timeline-root="true">
1386
+ <TimelineRowContent row={item} />
1387
+ </div>
1388
</div>
1382
- </div>
1389
+ </TimelineRowCtx>
1390
);
1391
+ const listExtraData = { identity: listIdentityKey, rowCount: rows.length, sharedState };
1392
1393
const forwardMinimapWheel = (event: WheelEvent) => {
1394
const scrollNode = listRef.current?.getScrollableNode();
@@ -1411,85 +1419,83 @@ const ConversationTimeline = memo(function ConversationTimeline({
1419
1420
return (
1421
<MarkdownFindContext value={findActive}>
1414
- <TimelineRowCtx value={sharedState}>
1415
- <TimelineRowActivityCtx value={activityState}>
1416
- <TooltipScrollDismissArea
1417
- ref={setTimelineViewportElement}
1418
- className="relative h-full min-h-0"
1419
- data-assistant-citation-viewport="true"
1420
- >
1421
- {onCiteAssistantText && citationThreadRef ? (
1422
- <AssistantSelectionToolbar
1423
- viewport={timelineViewportElement}
1424
- threadRef={citationThreadRef}
1425
- onCite={onCiteAssistantText}
1426
- />
1427
- ) : null}
1428
- <LegendList<MessagesTimelineRow>
1429
- ref={setTimelineList}
1430
- data={rows}
1431
- extraData={`${listIdentityKey}:${rows.length}`}
1432
- keyExtractor={keyExtractor}
1433
- getItemType={getItemType}
1434
- renderItem={renderItem}
1435
- estimatedItemSize={90}
1436
- initialScrollAtEnd={
1437
- !findActive && citationRequest === null && rememberedPosition?.atEnd !== false
1438
- }
1439
- // Legend needs a data refresh to mount new pins without a scroll event.
1440
- dataVersion={readyCitationRequest?.key ?? listIdentityKey}
1441
- {...(alwaysRender ? { alwaysRender } : {})}
1442
- onLoad={handleListLoad}
1443
- {...(anchoredEndSpace ? { anchoredEndSpace } : {})}
1444
- contentInsetEndAdjustment={anchoredEndSpace ? contentInsetEndAdjustment : 0}
1445
- maintainScrollAtEnd={
1446
- citationPositioning ||
1447
- (restoringThreadPosition && rememberedPosition?.atEnd === false) ||
1448
- anchoredEndSpace ||
1449
- !liveFollowEnabled ||
1450
- fullscreenAppRowId !== null ||
1451
- disclosureToggleSettling
1452
- ? false
1453
- : isWorking && !prefersReducedMotion && settlingListIdentity === null
1454
- ? TIMELINE_MAINTAIN_SCROLL_AT_END_SMOOTH
1455
- : TIMELINE_MAINTAIN_SCROLL_AT_END
1456
- }
1457
- maintainVisibleContentPosition={
1458
- findActive ||
1459
- citationPositioning ||
1460
- (restoringThreadPosition && rememberedPosition?.atEnd === false)
1461
- ? false
1462
- : maintainVisibleContentPosition
1463
- }
1464
- maintainScrollAtEndThreshold={1}
1465
- onScroll={handleScroll}
1466
- onItemSizeChanged={handleItemSizeChanged}
1467
- className={cn(
1468
- "messages-timeline-scroll scrollbar-gutter-both h-full min-h-0 overflow-x-hidden overscroll-y-contain [overflow-anchor:none]",
1469
- topFadeEnabled && "topbar-scroll-fade",
1470
- )}
1471
- ListHeaderComponent={listHeader}
1472
- ListFooterComponent={timelineListFooter}
1473
- />
1474
- <TimelineMinimap
1475
- items={minimapItems}
1476
- hasPersistentGutter={minimapHasPersistentGutter}
1477
- hitStripWidth={minimapHitStripWidth}
1478
- currentIndex={minimapCurrentIndex}
1479
- stripMap={minimapStripMap}
1480
- onWheel={forwardMinimapWheel}
1481
- onSelect={(item) => {
1482
- onManualNavigation();
1483
- void listRef.current?.scrollToIndex({
1484
- index: item.rowIndex,
1485
- animated: true,
1486
- viewOffset: 24,
1487
- });
1488
- }}
1422
+ <TimelineRowActivityCtx value={activityState}>
1423
+ <TooltipScrollDismissArea
1424
+ ref={setTimelineViewportElement}
1425
+ className="relative h-full min-h-0"
1426
+ data-assistant-citation-viewport="true"
1427
+ >
1428
+ {onCiteAssistantText && citationThreadRef ? (
1429
+ <AssistantSelectionToolbar
1430
+ viewport={timelineViewportElement}
1431
+ threadRef={citationThreadRef}
1432
+ onCite={onCiteAssistantText}
1433
/>
1490
- </TooltipScrollDismissArea>
1491
- </TimelineRowActivityCtx>
1492
- </TimelineRowCtx>
1434
+ ) : null}
1435
+ <LegendList<MessagesTimelineRow>
1436
+ ref={setTimelineList}
1437
+ data={rows}
1438
+ extraData={listExtraData}
1439
+ keyExtractor={keyExtractor}
1440
+ getItemType={getItemType}
1441
+ renderItem={renderItem}
1442
+ estimatedItemSize={90}
1443
+ initialScrollAtEnd={
1444
+ !findActive && citationRequest === null && rememberedPosition?.atEnd !== false
1445
+ }
1446
+ // Legend needs a data refresh to mount new pins without a scroll event.
1447
+ dataVersion={readyCitationRequest?.key ?? listIdentityKey}
1448
+ {...(alwaysRender ? { alwaysRender } : {})}
1449
+ onLoad={handleListLoad}
1450
+ {...(anchoredEndSpace ? { anchoredEndSpace } : {})}
1451
+ contentInsetEndAdjustment={anchoredEndSpace ? contentInsetEndAdjustment : 0}
1452
+ maintainScrollAtEnd={
1453
+ citationPositioning ||
1454
+ (restoringThreadPosition && rememberedPosition?.atEnd === false) ||
1455
+ anchoredEndSpace ||
1456
+ !liveFollowEnabled ||
1457
+ fullscreenAppRowId !== null ||
1458
+ disclosureToggleSettling
1459
+ ? false
1460
+ : isWorking && !prefersReducedMotion && settlingListIdentity === null
1461
+ ? TIMELINE_MAINTAIN_SCROLL_AT_END_SMOOTH
1462
+ : TIMELINE_MAINTAIN_SCROLL_AT_END
1463
+ }
1464
+ maintainVisibleContentPosition={
1465
+ findActive ||
1466
+ citationPositioning ||
1467
+ (restoringThreadPosition && rememberedPosition?.atEnd === false)
1468
+ ? false
1469
+ : maintainVisibleContentPosition
1470
+ }
1471
+ maintainScrollAtEndThreshold={1}
1472
+ onScroll={handleScroll}
1473
+ onItemSizeChanged={handleItemSizeChanged}
1474
+ className={cn(
1475
+ "messages-timeline-scroll scrollbar-gutter-both h-full min-h-0 overflow-x-hidden overscroll-y-contain [overflow-anchor:none]",
1476
+ topFadeEnabled && "topbar-scroll-fade",
1477
+ )}
1478
+ ListHeaderComponent={listHeader}
1479
+ ListFooterComponent={timelineListFooter}
1480
+ />
1481
+ <TimelineMinimap
1482
+ items={minimapItems}
1483
+ hasPersistentGutter={minimapHasPersistentGutter}
1484
+ hitStripWidth={minimapHitStripWidth}
1485
+ currentIndex={minimapCurrentIndex}
1486
+ stripMap={minimapStripMap}
1487
+ onWheel={forwardMinimapWheel}
1488
+ onSelect={(item) => {
1489
+ onManualNavigation();
1490
+ void listRef.current?.scrollToIndex({
1491
+ index: item.rowIndex,
1492
+ animated: true,
1493
+ viewOffset: 24,
1494
+ });
1495
+ }}
1496
+ />
1497
+ </TooltipScrollDismissArea>
1498
+ </TimelineRowActivityCtx>
1499
</MarkdownFindContext>
1500
);
1501
});