Skip to content

Reduce chat timeline work-row rerenders#3544

Draft
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/component-performance-optimization-c54a
Draft

Reduce chat timeline work-row rerenders#3544
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/component-performance-optimization-c54a

Conversation

@cursor

@cursor cursor Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Removed the list-wide timeline activity context that every simple work row consumed.
  • Added turnInProgress to derived work-row data so only rows belonging to the currently unsettled turn receive changed render props.
  • Kept revert-button disabled state in a narrow context consumed only by revert controls.
  • Moved touched timeline effects into named hooks to keep component bodies render-focused.
  • Added row-derivation tests proving inactive work rows are structurally reused when a different turn settles.

Why

React Doctor identified chat/timeline performance hotspots, including ChatView and MessagesTimeline compiler/rerender concerns. Manual inspection found TimelineRowActivityCtx broadcasting active-turn state to every SimpleWorkEntryRow, causing long timelines to rerender old work rows whenever the current turn toggled running/settled. Row-scoping that state preserves the existing structural-sharing strategy and narrows updates to rows whose visual state can actually change.

UI Changes

No intentional UI appearance changes. React Scan before/after recordings were captured with a temporary uncommitted harness rendering the real MessagesTimeline and toggling active-turn state:

  • Before: react_scan_before_timeline_context_rerenders.mp4
  • After: react_scan_after_row_scoped_rerenders.mp4

The after recording shows rerender highlighting scoped away from inactive work rows compared with the before recording.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Validation:

  • npx -y react-doctor@latest apps/web --verbose --category performance (reported broader existing performance findings; used to guide hotspot selection)
  • pnpm --dir apps/web exec vp test run --passWithNoTests --project unit src/components/chat/MessagesTimeline.logic.test.ts src/components/chat/MessagesTimeline.test.tsx -> 38 tests passed
  • NODE_OPTIONS="--experimental-strip-types" pnpm exec vp check -> passed with 0 errors / 20 pre-existing warnings
  • NODE_OPTIONS="--experimental-strip-types" pnpm exec vp run typecheck -> passed
Open in Web View Automation 

Note

Reduce chat timeline work-row rerenders by computing turnInProgress per work row

  • Moves the activeTurnInProgress global flag out of MessagesTimeline props and instead computes a turnInProgress boolean on each work row in MessagesTimeline.logic.ts, set only when the row contains entries from the currently unsettled turn.
  • isRowUnchanged now checks turnInProgress equality so stable rows are reused across renders when a turn settles, avoiding unnecessary rerenders of prior work rows.
  • SimpleWorkEntryRow reads its own turnInProgress prop instead of a shared context, so only rows belonging to the active turn render as in-progress.
  • Replaces TimelineRowActivityCtx with a narrower TimelineRevertControlsCtx carrying a single disabled flag for RevertUserMessageButton.
  • Several inline effects in MessagesTimeline are extracted into dedicated hooks (useFoldToggleSettlingReset, useLatestTurnFoldState, useInitialTimelineEndScroll, useWorkingTimerText, usePreserveWorkGroupAnchorOnExpand) to isolate side-effects.

Macroscope summarized 9b74066.

cursoragent and others added 2 commits June 24, 2026 16:09
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant