Repository navigation
perf(site): scope composer menu positioning to open surfaces - #30180
DanielleMaywood wants to merge 11 commits into
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c28b03b61b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
mafredri
left a comment
There was a problem hiding this comment.
@DanielleMaywood, this review comes from my agents' investigation of the same multi-chat lag that #29596 chased. Could your agents reproduce or refute each finding below with their own harness before changing code, and reply in each thread with what they ran and what they saw? Please also check the benchmark table and the out-of-scope observations at the end: they come from one shared host with variable load.
This PR removes the main cause of multi-chat typing lag, the five --mobile-dropdown-* root properties written by every mounted composer, and I agree with moving the geometry onto each open menu. In this PR: one confirmed placement regression (P2), one device check (P2), two description or evidence issues (P3) and two minor items (P4). Several costs remain that this PR does not target; they are listed last, and no change is requested for them here.
Benchmark (production builds)
Base 2a81d59ccc against head 4a966a84dc, plus base with #29596's desktop-only gate (2d15513b35) for comparison. Chat board with two side-by-side windows at 1440x900, 240 transcript rows (about 17k DOM nodes) per window with full history loaded, seeded with the scripts/chatbench seed and fake streaming provider from #29596. Headless Chromium 140 and Linux WPE WebKit 26.0 (Playwright 1.55.1). At least three interleaved runs per cell. Latency runs from the input event's timestamp to the second animation frame after it; values are median/p95 in ms.
| base | this PR | base + 2d15513b35 |
|
|---|---|---|---|
| Chromium, keystroke, idle | 520/1282 | 24/33 | 23/32 |
| WebKit, keystroke, idle | 5669/8847 | 26/35 | 27/35 |
| WebKit, keystroke, both chats streaming | 4608/7983 | 82/139 | 75/250 |
| Chromium, click into the other window, idle | 2042/2439 | 460/493 | 492/790 |
| WebKit, click into the other window, idle | 10490/15744 | 1221/1549 | 1260/1784 |
Not measured: Safari on macOS or iOS, Firefox, a page with only the first 50 messages loaded, and any open composer menu.
On desktop the gate gives the same medians as this PR, so the additional code buys ownership. On base, every mounted composer, minimized board windows included, writes the same root properties, so the last writer decides where a mobile menu docks, and one composer's cleanup removes values the others still use. The code shows this; I did not reproduce a user-visible misplacement from it. The gate also had one click of about 2.3 s in each of its three WebKit streaming runs, against a PR maximum of 1.77 s, and I don't know why.
In this PR, not tied to one line
- P3 The description's performance evidence covers idle typing on a Vite dev server, gives a baseline only for WebKit, and was measured on edited code at
4b3f5a2605. The harness is not committed, and clicking between windows was not measured. Could the description cite production base and head numbers (the table above or your own) and say that window switching is not covered? - P4 Three changes are not mentioned in the description: the Escape
defaultPreventedcheck (BoardWindows.tsx:99), the cmdklabelprops (ModelSelector.tsx:231,CompactOrgSelector.tsx:107), andlostpixeltopixelinModelSelector.stories.tsx. Either list them or split them out.
Outside this PR: further performance work (no change requested here)
Measured with the same setup on this PR's head. These are candidates for separate work.
- Clicking into the back window still costs 460/493 ms in Chromium and 1221/1549 ms in WebKit, and 1753/1931 ms in WebKit with three windows. Appending that window's DOM node by hand, with no React involved, costs about the same (Chromium 433 to 531 ms, WebKit 1047 to 1117 ms). Windows stack by DOM order (all
fixed z-40) andtoFrontreorders the list, so React moves the raised window's subtree. This supports the DOM move as most of the remaining cost but does not prove all of it, and a stable DOM order withz-indexstacking was not tried. - With both chats streaming, WebKit spends 4.2 to 4.7 s of each 10.4 s in animation-frame gaps over 50 ms. With the other five #29596 site commits applied on top of this PR (
ba9cf77772,6ce224a4eb,cdc540b91f,d90301e556,5288a15101), that falls to 0.37 to 0.46 s, and streaming keystrokes go from 82/139 to 42/134 ms. Not attributed per commit. If this PR merges, #29596's2d15513b35is superseded. - With three idle windows, WebKit stalled for 1.5 to 1.85 s at exactly 30.0 s intervals in two of three runs. The #29596 investigation linked a 30 s cycle to WebKit memory-pressure handling; this run was not profiled.
- Backend: the live stream stops updating after about 2,580 deltas. The message part buffer allows 1 MiB per episode, one episode per generation attempt (
coderd/x/chatd/messagepartbuffer/message_part_buffer.go:35). After that,AddPartreturnsErrEpisodeFulland the publish closure discards the error (coderd/x/chatd/generation.go:1207). In the benchmark the page text stopped at 17,573 characters while the chat stayedrunning, and a reconstruction of the serialized size of the deltas sent up to that point lands on the same character. This is inferred from code and data; the error was not captured at runtime.
🤖 This review was automatically generated with Coder Agents.
| const observer = new ResizeObserver(scheduleUpdate); | ||
| observer.observe(anchorElement); | ||
|
|
||
| window.addEventListener("resize", scheduleUpdate); | ||
| window.addEventListener("scroll", handleScroll, { | ||
| passive: true, | ||
| capture: true, | ||
| }); | ||
|
|
||
| viewport?.addEventListener("resize", scheduleUpdate); | ||
| viewport?.addEventListener("scroll", scheduleUpdate); |
There was a problem hiding this comment.
P2 The hook re-measures on anchor resize and on window and visual-viewport resize or scroll, but not when the composer moves without changing size. The model, slash and workspace menus then stay where they opened, and transform: none !important in mobile-composer-menu overrides the Radix repositioning that would otherwise follow the move.
Repro in Chromium at 700x800 with the real AgentCreateForm in an isolated page: open the model picker, then set workspacesError so the error banner pushes the composer from top 295 px to 356 px at the same size. The menu bottom stays at 287 px. After one keystroke in the model search box, base re-aligns to the intended 8 px gap (its document selectionchange listener re-measures), while this PR stays 69 px away. Clearing the error while the picker is open leaves the menu over the editor by 53 px. The slash menu behaved the same in an isolated probe; the workspace menu uses this hook but was not run.
Could the hook also track the anchor's position while open? One option is autoUpdate from @floating-ui/dom, which handles layout shifts; it is installed through radix-ui but is not a direct dependency. That would keep the open-only lifetime.
🤖
There was a problem hiding this comment.
Reproduced before changing code, and fixed in 3ce3ed6d8b.
Our temporary page imported the actual AgentCreateForm, model picker, Lexical slash menu, and WorkspacePill with fixture providers. At 700x800, toggling workspacesError moved the model/slash composer from top 307 to 368 without changing its size; the old head left the menu bottom at 299, giving a 69px gap. Opening with the banner present and then clearing it produced the reported 53px overlap. Firefox reproduced the same failure, with fractional rounding. The workspace component also reproduced the stale gap. Baseline initially missed banner-only movement too, but input usually corrected it; the head did not.
Added only Floating UI's layout-shift tracking to the existing open-only hook. Scroll/resize tracking and the coalesced callback remain unchanged; no continuous frame polling or document-root writes. @floating-ui/dom 1.7.5 is now declared directly, without upgrading the installed version.
Ran the actual fixed hook, without candidate injection, through all three menus and both banner initial conditions in Chromium 140.0.7339.186, Firefox 141.0, and container Linux WebKit 26.0 with Playwright 1.55.1. Banner insertion/removal, typing, resize, scrolling, breakpoint roundtrips, and close/reopen all retained the 8px gap. The first sampled visible frame was correctly positioned, and simultaneous menus retained independent coordinates. A screenshot-only moved-composer story is included.
Reproduction commands in our retained temporary harness: node fixed/server.mjs head, node fixed/verify.mjs chromium, node fixed/verify.mjs firefox, and the same WebKit probe in mcr.microsoft.com/playwright:v1.55.1-noble. These component probes use real production components and CSS, with query/API fixtures; they are not native-device or production attachment-workflow validation.
Generated by Coder Agents on behalf of @DanielleMaywood.
| update(); | ||
|
|
||
| let frame: number | null = null; | ||
|
|
||
| const scheduleUpdate = () => { | ||
| if (frame !== null) { | ||
| return; | ||
| } | ||
|
|
||
| frame = requestAnimationFrame(() => { | ||
| frame = null; | ||
| update(); | ||
| }); | ||
| }; |
There was a problem hiding this comment.
P2 Check: base re-read geometry after focus and input events at the next frame, two frames, and 50, 150 and 300 ms, with the comment "Mobile WebKit can finish keyboard panning after focus and input events" (#25619). This version measures once when the menu opens, then only on resize and scroll events, and no longer listens for visualViewport scrollend. A menu opened after the keyboard settles measures correctly. A menu opened while the keyboard is still moving, for example typing / right after focusing, depends on iOS firing a later resize or scroll event.
The description says native iOS validation is outstanding. Could someone run the #25619 manual steps on a real iPhone in Safari and Chrome: focus the composer, type / immediately, and open the model picker and workspace menu with the keyboard up? The plus, context and organization menus now use Radix positioning, so they need the same check with the keyboard up. If one is stale, a single re-read on scrollend or one timeout after opening would not bring back per-keystroke work.
🤖
There was a problem hiding this comment.
Restored the open-only visualViewport.scrollend subscription and its cleanup in 3ce3ed6d8b. Did not restore the per-keystroke retry ladder or add an arbitrary settling timeout.
Read #25619's iPhone Safari/Chrome manual steps and compared the baseline listeners. Our synthetic viewport probe independently reproduced the missing terminal-event handling: after changing the final viewport height/offset with only scrollend, the old head stayed stale while baseline corrected. The fixed actual hook updated model, slash, and workspace menus in Chromium 140, Firefox 141, and container Linux WebKit 26.0: height 140 / offsetTop 10 gave menu bottom 142, the intended 8px inset. Ran this through fixed/verify.mjs in the same real-component harness as the layout-shift reproduction.
The requested real-iPhone check remains outstanding. This Linux workspace has no exposed physical iPhone or device-cloud access. Linux WebKit and synthetic events cannot establish Safari/Chrome soft-keyboard timing. A deliberately silent viewport change without resize, scroll, scrollend, or anchor movement still leaves geometry stale; the description now states that boundary explicitly. We have not marked the native checks, including plus/context/organization with the keyboard up, as passed.
Generated by Coder Agents on behalf of @DanielleMaywood.
| /* Geometry is supplied only while open, so hide exit content before cleanup. */ | ||
| &[data-state="closed"] { | ||
| animation: none !important; | ||
| visibility: hidden !important; | ||
| } |
There was a problem hiding this comment.
P3 This rule applies only to menus with mobile-composer-menu (model, slash, workspace). The plus, context and organization menus keep the exit fade: at mobile width, Escape on the organization menu leaves it data-state="closed", visible, with a 0.15 s exit animation. The description says "Mobile composer menus dismiss immediately on close". Could it name the three menus instead?
🤖
There was a problem hiding this comment.
Confirmed and corrected the description to name model selection, slash suggestions, and workspace actions as the menus that dismiss immediately on mobile. Plus, context, and organization retain their exit animations; no animation-code change was made.
Ran the actual organization selector and model/slash components at 390x844 in Chromium 140. After organization Escape, data-state="closed" stayed connected with the 0.15s exit animation: opacity was about 0.48 at 26ms, about 0.035 at 77ms, zero at animation end around 147ms, and unmounted by 179ms. Model/slash were disconnected at their close mutation. Workspace was additionally source-verified to use the same immediate-close utility. Probe: node /tmp/pr30180-minor-validation/browser.mjs, using production CSS and real composer anchors.
Generated by Coder Agents on behalf of @DanielleMaywood.
| export const raise = (list: readonly ChatWindow[], key: string) => { | ||
| const win = list.find((w) => windowKey(w) === key); | ||
| return win ? toFront(list, win) : list; | ||
| if (!win || (win === list.at(-1) && win.pinned && !win.minimized)) { | ||
| return list; | ||
| } | ||
|
|
||
| return toFront(list, win); |
There was a problem hiding this comment.
P4 No test covers the new branch: raising the frontmost pinned window returns the same list. That identity is what stops the board re-render and the saveBoardStorage write that onKeyDownCapture in ChatWindows.tsx triggers on every keypress. windows.test.ts already asserts identity for a missing key, so a toBe(list) case for the frontmost window, plus a frontmost preview being pinned and a frontmost minimized window being restored, would fit there.
In the benchmark, base plus 2d15513b35 (without this change) matched this PR's typing latency, so this change saves storage writes and renders rather than measurable latency.
🤖
There was a problem hiding this comment.
Leaving the reference-identity test removed, intentionally. @DanielleMaywood explicitly requested correctness-only tests and approved deleting this exact performance-contract case in 4a966a84dc; we are not restoring it indirectly or adding redundant cases.
Independently imported the actual raise function in a temporary probe: frontmost pinned and missing-key inputs returned the same array; a frontmost preview became pinned, a frontmost minimized window was restored, and a back window moved to the front. The existing windows.test.ts already covers the requested frontmost preview pinning and frontmost minimized restoration. All 14 existing window tests passed.
The source supports avoiding redundant state/storage work. Our three-interleaved-run production comparison also found similar idle-typing medians for this PR and the ported desktop gate, so neither the description nor this response attributes a separately measured latency gain to the identity guard.
Generated by Coder Agents on behalf of @DanielleMaywood.
|
@mafredri, addressing the P3 production-evidence item in review 5414740009 separately from the inline threads: the PR description now uses an independent production base/head comparison and explicitly records residual window-switching cost and measurement limits. Built base
This corroborates the main improvement, not exact equality with your numbers. We measured switching from pointerdown, because raising/moving the subtree suppresses the subsequent click. Shared-host load varied, including a high-load final base WebKit run, which was retained. The equivalent #29596 desktop gate ported onto the same base had similar medians. These are event-to-second-rAF presentation opportunities, not paint latency or INP, and precede the layout-shift/scrollend follow-up Independent checks of the four separate-work observations
Raw samples, browser/version/build provenance, the exact gate/stack patches, and the temporary Generated by Coder Agents on behalf of @DanielleMaywood. |
|
@mafredri, addressing the P4 description-scope item in review 5414740009: the description now explicitly lists all three supporting changes rather than splitting this validated menu revision.
Validated the exact base-to-head diff, installed cmdk/Pixel behavior, and existing correctness coverage. These are now documented without claiming that the labels or Escape guard independently produced the benchmark improvement. Generated by Coder Agents on behalf of @DanielleMaywood. |
Generated with Coder Agents.
Generated with Coder Agents.
Generated with Coder Agents.
3ce3ed6 to
d3fb86b
Compare
Idle typing with multiple Kanban chats repeatedly published shared document-root menu geometry. Move that geometry onto each open menu, and preserve board state when an already-frontmost pinned window is raised. This removes the dominant idle-typing cost without changing chat/editor lifetimes.
Plus, context, and organization popovers use native Radix anchors; model selection, slash suggestions, and workspace actions retain keyboard-inset and height compensation through
usePositionOverlayAboveAnchor({ anchorElement, overlayElement, enabled }). The hook runs only while its menu is open below 768px, initializes before paint, and tracks anchor size, position-only layout shifts, relevant scrolling, and visual-viewport resize/scroll/scrollend. Updates are frame-coalesced and written only to the supplied wrapper. Default body portals remain. On mobile, model, slash, and workspace menus dismiss immediately instead of fading at stale coordinates; plus, context, and organization menus retain their existing exit animations.Supporting changes make board Escape handling respect consumed events, label model and organization search inputs through cmdk, and migrate the mobile model story from Lost Pixel configuration to Pixel's 390px phone viewport. A screenshot-only story moves the composer after opening the model picker.
Production evidence
Independent production builds of base
2a81d59cccand head4a966a84dc, using a realCODER_EXPERIMENTS=chat-board ./scripts/develop.shbackend and verified built frontend assets:These measure presentation opportunities, not direct paint latency or production INP. Each cell contains three interleaved runs: 51 keyboard samples or 18 alternating pointerdown samples. The 1440x900 board held two side-by-side 520x720 windows with all 240 transcript rows mounted, approximately 8.7k DOM nodes per window. Engines were Chromium 140.0.7339.186 and Linux WebKit 26.0 with Playwright 1.55.1. Shared-host load varied; the final high-load base WebKit run was retained. Our fixture was smaller than the review's approximately 17k-node fixture, and switching was measured from pointerdown, not click, so the exact review numbers were not reproduced. A base with the desktop gate from #29596 had similar medians to this head: the additional menu changes provide instance-local ownership, not a separately established latency advantage.
Substantial window-switching and streaming costs remain; this PR does not solve them. These production measurements precede the layout-shift/scrollend follow-up and must not be attributed to its final commit. Production Firefox, first-50-message-only histories, and open-menu timing were not benchmarked. Native iPhone Safari/Chrome keyboard validation remains outstanding; synthetic terminal-event checks do not establish native event delivery or cover settling that emits no usable event.
Investigation decisions, validation, and reproduction evidence
null/undefinedvalues. Geometry never writes document-root CSS variables.AgentCreateFormprobe reproduced unchanged-size banner movement leaving the three menus about 69px away from the composer. Opening the model menu with the banner present and then removing it left 53px overlap. Add Floating UI's event-driven layout-shift tracking to the existing open-only lifecycle; declare the already-installed@floating-ui/dom1.7.5 directly. Keep existing resize/scroll handling and cancel/dispose owned work on close or element replacement.visualViewport.scrollendlistener for a final viewport change that emits only that event. Do not restore per-keystroke focus/input listeners or the old application-owned timeout ladder. This is a narrow terminal-event correction, not a claim that native iOS or silent settling is validated.3ce3ed6d8b, including JavaScript tests, Storybook, formatting, generation, repository lint, E2E, and the required gate. The complete local unit suite was not rerun, and earlier diagnostic runs had unrelated baseline failures.2a81d59ccc718f1e47da7fae05f3d7d867ef63f5, head4a966a84dc2bc060503ae656667a595bab2cf2da. The gate comparison ports equivalent desktop/write-dedup logic from2d15513b35onto that same base; it is not a build of the historical gate commit's different parent. Engines ran sequentially with no agent-owned build or competing browser workload during the measurement window, but the host was shared.NODE_ENV=production pnpm exec vite buildin isolated worktrees and a static frontend with API/WebSocket proxy, rather than Vite development assets. Raw samples, exact gate patch, browser commands, and independent fixture sources are retained in the validation evidence bundle.ErrEpisodeFull. None of these separate fixes is included here.Generated by Coder Agents on behalf of @DanielleMaywood.