Repository navigation
perf(web): stop sidebar rows re-rendering their context menu tree - #24107
Conversation
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the trigger fix removes the re-render at its cause, renders the same DOM, and adds an already-hoisted dependency. Notes
[DESIGN-REVIEWED] b259294 Description read[DESCRIPTION-READ] a87384d92add64426a40470b261497cef144bb923d15ebf337257d580cf0d7b8 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. This is a render-performance refactor: the session row keeps the same DOM, handlers and right-click menu, and the diff adds or changes no user-visible control, label or state. [UX-REVIEWED] b259294 Description read[DESCRIPTION-READ] 4cd68dae1b7ad108e4e278cca002b5408e89f4d17f1545ce12403d47f2a03b15 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. What this change shipsInventory (5 items) — 5 justifiedIntent: keep the sidebar responsive while sessions stream by stopping each row re-render from also re-rendering its right-click menu tree. This is a FIX (perf).
[FIRST-PRINCIPLES-REVIEWED] b259294 Description read[DESCRIPTION-READ] bfb30476130967db7c6c734a34c35ddc573e4e29ba0b21861c1da08b189fdbc0 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
7952c43 to
f7a8f85
Compare
|
span=first-principles:website/src/components/ui/context-menu.tsx Disposition: fixed in f7a8f85.
|
iamwhatever
left a comment
There was a problem hiding this comment.
Request changes at f7a8f85.
The fix looks sound: SessionRow already memoizes its menu content, so the memoized Radix tree with a constant Slot outlet removes the menu re-renders without changing the DOM or handlers, and CI is green.
Two items need an answer before approval:
- The PR body says folder header context menus are
left as a follow-up, and your disposition refers to that follow-up, but no issue tracks it (#24106 covers session rows only). Please open an issue for it and link it in the description, or drop the follow-up wording if no follow-up is planned. - The Design Review note on this head (comment) asks that the JSDoc state
contentmust be referentially stable, since an inlinecontentsilently loses the saving (context-menu.tsx L66-L77). It has no reply yet. A one-line JSDoc addition or a reply would clear it.
— crew-pr-reviewer (r126)
|
note (non-blocking): folder-header follow-up wording dropped The description no longer calls the folder header menus a follow-up. That bullet in |
|
span=design:website/src/components/ui/context-menu.tsx Disposition: fixed in 99b456f, which superseded the rebuttal first posted here.
|
f7a8f85 to
99b456f
Compare
|
note (non-blocking): both review items are addressed on 99b456f The first item, the folder-header follow-up wording, came out of the description at 03:14Z. The folder headers are now listed only as out of scope, with the reason. The second item is fixed in 99b456f. The |
|
question (non-blocking): could a maintainer re-run the fork GPT 6.1 and Opus 5.5 review lanes on 99b456f? Both check runs ended as "review incomplete" about two hours ago, and neither lane's comment has been updated past f7a8f85. The only change since that head is the two JSDoc lines in |
|
note (non-blocking): rebased on main, no behaviour change. b259294 is 99b456f on current main. No review lane had run on 99b456f, and main had moved 322 commits, including a class-name and rename-ref change in |
99b456f to
b259294
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
Approving b259294.
Both items from my r126 review are resolved. The description no longer promises a folder-header follow-up; it lists those menus as out of scope with the reason. The ContextMenuStableTrigger JSDoc now says content must be referentially stable (context-menu.tsx L41-L79).
The approach is sound. The Radix tree is memoized on the row's already-memoized menu content, and the changing row element reaches the trigger through a constant Slot outlet, so the DOM, handlers and ref stay the same (SessionRow.tsx L1125). The new direct dependency @radix-ui/react-slot 1.3.0 is the version already installed. All fork AI lanes pass at this head with no open concerns, and CI is green (PR Readiness success).
— crew-pr-reviewer (r133)
Problem / Motivation
Goal: A sidebar session row re-renders without re-rendering the Radix context menu tree around it.
Every render of a session row also rendered the row's ContextMenu root, Menu, MenuProvider, Popper, PopperProvider, PopperAnchor and ContextMenuTrigger. The row hands its
<div>toContextMenuTrigger asChild, that element is new on every row render, and each Radix layer re-renders when itschildrenprop changes. PopperAnchor also re-attaches its composed ref on each of those renders. The menu content was already memoized, so the menu showed nothing new.Why it matters
Rows re-render while background sessions stream and whenever a row moves. In the render benchmark's s1x5 scenario, 186 of 192 row renders also rendered the menu tree, and MenuProvider, ContextMenu, Popper and Menu were the four highest Radix render counts in the run.
Not a goal
What changed (motivation → approach → change)
Nothing changes on screen. A session row re-render no longer re-renders the row's right-click menu, which cuts the sidebar's render work while sessions stream (7920 component renders instead of 9780 in the benchmark below).
ContextMenuStableTriggerincomponents/ui/context-menu.tsxbuilds<ContextMenu><ContextMenuTrigger asChild>…</ContextMenuTrigger>{content}</ContextMenu>once per change ofcontent. The trigger's child is one constant outlet element. The outlet reads the caller's current element from context and renders it through RadixSlot, which merges the trigger's props and ref onto it the same wayasChilddoes. A new row element now re-renders only the outlet.SessionRowuses it in place of the plainContextMenuandContextMenuTriggerpair. The DOM and the handler order on the row are unchanged.website/package.jsonadds@radix-ui/react-slotas a direct dependency at 1.3.0, the version the menu packages already install.website/package-lock.jsongains only that root entry.Backwards compatibility
Compatible:
ContextMenuandContextMenuTriggerare unchanged, andContextMenuStableTriggeris a new export.Removes nothing: the row renders the same element with the same handlers, ref and menu content.
Tests
ContextMenuStableTrigger.test.tsxpins right-click opening the menu while the element's ownonContextMenuandonPointerDownstill run. It checks that a re-render updates the same DOM node without detaching its ref and that the menu still opens afterwards. It also checks that Escape on a keyboard-opened menu returns focus to the element.ChatSidebar.rowMemo.test.tsxnow counts RadixContextMenu.Rootrenders when a top insertion displaces 20 rows. It expects 1, for the new row only. On main it counts 21.vitest relatedon the two changed source files ran 987 files and 15,081 tests, all green.Proof: not provable -- frontend test (prove.py runs Python only). The rowMemo assertion was run against main's
SessionRow.tsxand failed with 21 against 1.Manual verification
Render benchmark from #23431 (
scripts/bench-render.mjs), applied locally on main 5631aab without and with this change. Scenario s1x5, desktop, 30 s, 3 runs per side. All 3 runs on each side gave the same counts.Session rows now cause 0 menu renders. The perf plan's target was an 80% drop in Menu, Popper and ContextMenu renders in this scenario, measured from the original baseline before the slot-list change (#23877): Menu 617, Popper 652, ContextMenu 732. This PR reaches ContextMenu -82%, Menu -76% and Popper -78%, so two of the three stop short of 80%. What remains comes from other owners, not session rows. The ContextMenu wrapper's 66 renders that remain come from MessageContextMenu (42) and folder headers (24). Menu's 145 are those 66 plus 79 dropdown menus, mostly on transcript messages.
Screenshots / video
Why no screenshot: the row renders the same DOM and the same menu, only fewer times.
Related Issues
Fixes #24106
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)