Repository navigation
perf(website): keep the session list mounted while the sidebar is closed - #37116
Conversation
|
Sidebar reopen, main (left) vs this PR (right). Same 222-session fixture, CPU slowed 4x, the two takes recorded one after the other on the same host. The overlay is the longest main-thread task each reopen produced (main: 474 / 521 ms; this PR: 209 / 155 ms in this take). Recorded from 65c701a against the built SPA with the stubbed dashboard API (synthetic sessions, no real data). |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: every item serves the measured reopen freeze, and each rider fixes a behaviour that keeping the list mounted would otherwise break. Not checked: Safari/Firefox ResizeObserver firing on reattach, which the scroll and reveal re-runs rely on. What this change shipsInventory (7 items) — 7 justifiedIntent: reopening the sessions sidebar or phone drawer should no longer freeze the page while the list is rebuilt. This is a FIX (perf).
[FIRST-PRINCIPLES-REVIEWED] 36be2c9 Description read[DESCRIPTION-READ] b467516feed335e06395287280e4745c23c81a34dd422c917aea54a223724eca That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check: this is a performance change that adds or changes no user-visible control. The sidebar and drawer look and open the same as before, and recordings of both are attached. Notes
[UX-REVIEWED] 36be2c9 Description read[DESCRIPTION-READ] c902d0bad014b4af2dc3fc6f92d9b72b1f7a36eac2e12e61e648064584e651b8 That sha256 names everything this verdict read: the PR description, plus the 5 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 |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The list is kept mounted and moved between hosts instead of rebuilt, which removes the measured cause. Each consumer that relied on unmount-on-close is handled: scroll position, reveal requests, open menus and layers, and the drawer slot swap. The recordings show this revision. Notes
[DESIGN-REVIEWED] 36be2c9 Description read[DESCRIPTION-READ] da8655144ea29fed4630842abb537efd6138502b62baac20de1296ea58d27744 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 |
GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- website/src/hooks/useLaneScrollMemory.ts:144 -- Reopen restoration overrides a pending folder reveal
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 is downgraded: blocking on it isn't proportionate. Harm is LOW. F1: The failure needs all of these: a remembered anchor for the lane ( False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
65c701a to
cbb60c7
Compare
|
|
|
Scope change, asked for by the PR owner: the phone sessions drawer had the same cause (every open mounted the list again, about 460-900 ms at 4x CPU), so it is now covered too. The Goal line, Why it matters and Not a goal were edited for that reason only; "the phone drawer is unchanged" was removed from Not a goal. |
|
Recordings for head cbb60c7, main (left) vs this PR (right). Same 222-session fixture, CPU slowed 4x, the two takes recorded one after the other on the same host (load 20-24 during these takes). The overlay is the longest main-thread task each reopen produced. Phone drawer, 412x915 touch (main: 826 / 793 ms; this PR: 180 / 209 ms in this take): Desktop sidebar, 1280x800 (main: 478 / 463 ms; this PR: 157 / 236 ms in this take): Built SPA with the stubbed dashboard API: synthetic sessions, no real data. The timing table in the description comes from the interleaved runs at lower load, not from these takes. |
cbb60c7 to
2c4524d
Compare
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 20% chance that this change introduces a defect, above the 12% limit for approving on its own. Performance fix that keeps ChatSidebar mounted, portalled into a host element the drawer adopts while open and releases when closed. It handles the four things that relied on the list being unmounted: scroll memory restores when the lane comes back, reveals wait while the list is out of the document, menus close through a subscription while off screen, and the scope's overlay container leaves the document so hidden dialogs no longer claim Escape (this fixes the GPT lane's finding on the earlier head). It also handles the drawer swapping its slot. Checked against callers: the width is reported from state, not measured from the DOM; the guide registry ignores elements not in the document; Modal, the focus trap and popover stand down while off screen; the shortcut order still reads the detached DOM. Each behaviour has a test that fails without its change. Most CI and every AI lane on this head were still pending at decision time. No concrete regression path found. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
2c4524d to
54e89c2
Compare
|
|
|
|
54e89c2 to
5b70d74
Compare
5b70d74 to
ce8ecc9
Compare
Reopening the sessions sidebar on desktop, or the sessions drawer on a phone, mounted the whole session list again in one main-thread task: about 90-150 ms on desktop and 100-160 ms on a phone for a long list, four times that on a slow CPU. The list now renders into a host element that the drawer adopts while open and lets go of when closed, so reopening puts the same list back on screen. A phone/desktop switch still mounts it afresh. Taking the list out of the document drops the lane's scroll offset, so the lane scroll memory also restores its anchor row each time the lane comes back on screen, not only on mount. A reveal request (a folder or session picked in the command bar) that arrives while the list is out of the document now waits for it to come back, as it waited for the mount before. While closed, the kept list is marked hidden to its overlay layers, so a menu, context menu or select it had open closes as it does on a switch to another Crew. Other layers it opened go with the scope's own overlay container and come back on reopen, and the drawer slot lets go of the list only if it still holds it. The scope's container leaves the document while the sidebar is closed, so a dialog in it does not claim the composer's Escape, and its layers learn about the close through a subscription, so closing re-renders only the layers that read it.
ce8ecc9 to
36be2c9
Compare
|
|
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed 36be2c9b5d. Approving.
What I checked:
AdoptPaneHostonly removes the host when it still holds it, so a phone/desktop slot swap that adopts first and unmounts second keeps the list in place.OffScreenOverlayScopetakes its own overlay container out of the document while closed, so a dialog left open there no longer answersanotherEscapeOwnerIsOpen. Menus close through the subscription inuseCloseWhenCrewHidden, anduseLocalCrewHiddenreads the same signal throughuseSyncExternalStore, so a close does not re-render every menu row.useLaneScrollMemory:restore()callsstop()first, which removes the user-intent listeners, so repeated reattaches do not stack listeners. TheResizeObserverrestores only on a hidden-to-shown change.reveal.ts: both reveal effects return early while the root is out of the document, andshownTickruns them again on reattach, so a request made while closed still lands, as before.- The list is not kept in embed mode (
keepPaneMounted = !embedMode), and a form switch still mounts it afresh through the key.
Locally on this head: the 5 changed test files pass (62 tests), and tsc --noEmit is clean. CI is all green, including UX Review and PR Readiness.



Problem / Motivation
Goal: Reopening the sessions sidebar on desktop, or the sessions drawer on a phone, no longer freezes the page while the session list is built again.
Every reopen mounted the whole session list again (rows, menus, drag-and-drop) in one main-thread task. With a long list the page stops responding for about 100 ms at normal CPU speed, and for 400-900 ms on a slow CPU, while the drawer slides in.
Why it matters
Opening and closing the sessions list is one of the most common actions on the chat page, on desktop and on a phone. Clicks, typing and streaming output stall for as long as the reopen blocks.
Not a goal
What changed (motivation → approach → change)
Cause:
OverlayDrawerunmounts its children while closed, so every reopen mountedChatSidebaragain. A trace of one desktop reopen shows one React render of 100+ ms; layout is 13-22 ms of it.Approach: keep the list mounted and move it instead of rebuilding it.
SessionsSidebarChromerendersChatSidebarthrough a portal into a host element it owns. While the sidebar or drawer is open, the drawer adopts that host; when it closes, it lets go of it. Reopening puts the same list back on screen. The list mounts on the first open and is kept from then on; a phone/desktop switch mounts it afresh, as before. Closed, it takes the same store updates it takes while open.Four things depended on the list being unmounted while closed:
useLaneScrollMemoryrestores the recorded top row again when the lane comes back on screen, not only on mount.chat-sidebar/reveal.tsnow leaves the request pending while the list is out of the document and runs it when the list comes back.OffScreenOverlayScope(components/overlayRoot.tsx): its menus, context menus and selects close, as on a switch to another Crew;useLocalCrewHiddenreads true inside it, so a modal there ignores Escape; and every other layer it opened sits in the scope's own overlay container, which leaves the document while closed, so a dialog in it does not claim the composer's Escape, and comes back on reopen. The menus learn about the close through a subscription, not a changed context value, so closing re-renders only the layers that read it; a context value made every menu in the list re-render and added about 40 ms per close on a phone at CPU 4x.The lane scroll memory spec in
docs/system-specs/modules/learn-cron-dashboard.mddescribes the kept list.Fixture: 222 sessions, 100-row transcript, headless Chromium, builds alternated in one script with a main-vs-main (A/A) pair in every round.
The four rows above are from this head on the current main, with main's own pair (A/A) in every round, each round's runs within 2 of each other in load; one desktop CPU 4x round whose load moved more than that is left out. Closing at CPU 4x: main 0-77 ms on a phone and 54-202 ms on desktop, this PR 0-59 and 58-95 ms, so closing is no slower. The heap and node cost while closed is the same list that is there while open. The streaming and memory rows were measured on an earlier version of this change with the same desktop path.
Backwards compatibility
Compatible: the sidebar and drawer show the same list, keep their scroll position and still run a reveal requested while closed; only when the list mounts changes.
Removes nothing: no path, key, record or function is removed.
Tests
ChatPage.sidebarKeepMounted.test.tsx: closing the desktop sidebar, and the phone drawer, takes the list off screen without unmounting it, and reopening shows the same instance. Both fail on main. Two more cases close the sidebar with a real shared menu and a hand-rolled dialog layer open inside the list: the menu closes, and the layer leaves the document (soanotherEscapeOwnerIsOpen()is false) and the same one comes back on reopen. Each fails withoutOffScreenOverlayScope; the dialog case also fails on the previous head, where the container was only undisplayed.overlayRoot.test.tsx: inside an off-screen scopeuseLocalCrewHiddenreads true, and aModalopen there ignores Escape. Both fail on the previous head.AdoptPaneHost.test.tsx: when a newer slot adopts the host before the older slot unmounts, the host stays in the newer slot. Fails without the ownership check.useLaneScrollMemory.reattach.test.tsx: after the lane leaves the document and comes back with its offset reset, the recorded row is scrolled back to the top. Fails on main.ChatSidebar.folderSearch.test.tsx: a folder reveal, and a session reveal, requested while the sidebar is out of the document stay pending and run once it is back. Both fail without thereveal.tschange.ChatInput.approval.test.tsxand fail the same way on unmodified main (6a61c8465f3).Proof: not provable -- frontend test (prove.py runs Python only)
Manual verification
Against the built SPA with the stubbed dashboard API in headless Chromium: scrolled the desktop lane to
perf-s088, closed and reopened. Main and this PR both come back withperf-s088at the top; without the scroll-memory change the lane came back at the top. The phone drawer renders the same as on main (screenshots compared frame by frame in the recording).Not checked: Safari, Firefox, a real gateway and a real phone.
Screenshots / video
Same fixture, CPU slowed 4x, the two takes recorded one after the other. The overlay is the longest task each reopen produced. On main the list area stays empty or frozen while the list mounts; here it opens with its rows.
Related Issues
None filed. Found while measuring frontend render cost for the frame-time goal.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)