Reduce chat timeline work-row rerenders#3544
Draft
cursor[bot] wants to merge 2 commits into
Draft
Conversation
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
turnInProgressto derived work-row data so only rows belonging to the currently unsettled turn receive changed render props.Why
React Doctor identified chat/timeline performance hotspots, including
ChatViewandMessagesTimelinecompiler/rerender concerns. Manual inspection foundTimelineRowActivityCtxbroadcasting active-turn state to everySimpleWorkEntryRow, 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
MessagesTimelineand toggling active-turn state:react_scan_before_timeline_context_rerenders.mp4react_scan_after_row_scoped_rerenders.mp4The after recording shows rerender highlighting scoped away from inactive work rows compared with the before recording.
Checklist
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 passedNODE_OPTIONS="--experimental-strip-types" pnpm exec vp check-> passed with 0 errors / 20 pre-existing warningsNODE_OPTIONS="--experimental-strip-types" pnpm exec vp run typecheck-> passedNote
Reduce chat timeline work-row rerenders by computing
turnInProgressper work rowactiveTurnInProgressglobal flag out ofMessagesTimelineprops and instead computes aturnInProgressboolean on eachworkrow inMessagesTimeline.logic.ts, set only when the row contains entries from the currently unsettled turn.isRowUnchangednow checksturnInProgressequality so stable rows are reused across renders when a turn settles, avoiding unnecessary rerenders of prior work rows.SimpleWorkEntryRowreads its ownturnInProgressprop instead of a shared context, so only rows belonging to the active turn render as in-progress.TimelineRowActivityCtxwith a narrowerTimelineRevertControlsCtxcarrying a singledisabledflag forRevertUserMessageButton.MessagesTimelineare extracted into dedicated hooks (useFoldToggleSettlingReset,useLatestTurnFoldState,useInitialTimelineEndScroll,useWorkingTimerText,usePreserveWorkGroupAnchorOnExpand) to isolate side-effects.Macroscope summarized 9b74066.