Uh oh!
There was an error while loading. Please reload this page.
improvement(mothership-chat): memoize message rows for long-transcript load speed - #4520
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview
Reviewed by Cursor Bugbot for commit c2cbc7e. Configure here. |
Greptile SummaryThis PR memoizes the hot render path for Mothership chat by wrapping
Confidence Score: 5/5Safe to merge — changes are purely additive memoization with no altered data flow or side effects. All four files add memoization boundaries or stabilize existing references without touching data fetching, mutation, auth, or business logic. The ref-callback pattern for stabilizing onSubmit is standard React practice, the WeakMap cache correctly keys on object identity and relies on immutable React Query output (documented in JSDoc), EMPTY_BLOCKS is correctly hoisted, and the conditional early returns in AssistantMessageRow contain no hooks so they are safe. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant RQ as React Query
participant DM as toDisplayMessage
participant MC as MothershipChat
participant AMR as AssistantMessageRow (memo)
participant MsgC as MessageContent (memo)
participant CC as ChatContent (memo)
RQ->>DM: new PersistedMessage (structural sharing)
DM->>DM: WeakMap hit? return cached ChatMessage
DM-->>MC: stable ChatMessage reference
MC->>MC: useMemo(precedingUserContentByIndex, [messages])
MC->>MC: stableOnOptionSelect / stableOnWorkspaceResourceSelect (ref pattern)
MC->>AMR: message (stable ref), isStreaming, rowClassName
Note over AMR: memo compares props shallowly —<br/>historical rows skip re-render
AMR->>MsgC: blocks (EMPTY_BLOCKS or stable array)
Note over MsgC: memo + useMemo(parseBlocks)<br/>skips parse on stable blocks ref
MsgC->>CC: content, isStreaming
Note over CC: memo skips re-render for<br/>non-streaming messages
Reviews (2): Last reviewed commit: "improvement(mothership-chat): hoist EMPT..." | Re-trigger Greptile |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…sageContent memoized for block-free messages
waleedlatif1
commented
May 8, 2026
waleedlatif1
commented
May 8, 2026
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit c2cbc7e. Configure here.
Uh oh!
There was an error while loading. Please reload this page.
Summary
MessageContentandChatContentinReact.memoand memoizeparseBlocksso historical messages render once instead of on every parent state changeAssistantMessageRow/UserMessageRowfrom the inline.map(...)inmothership-chat.tsxand stabilize parent callbacks via the ref pattern so memo boundaries actually holdtoDisplayMessageso React Query's structural sharing keeps message references identical across refetchesNet effect: opening a long Mothership task (
/task/[taskId]) feels instant, scrolling stays smooth, and during streaming only the active message re-renders.Type of Change
Testing
Tested manually on long task transcripts. Streaming, edit, queue, and regenerate flows still work; React DevTools Profiler shows historical messages with 0 commits while a chunk arrives on the last message.
Checklist