Skip to content

Studio: make the chat and sidebar menus open without freezing the page - #10262

Merged
danielhanchen merged 12 commits into
unslothai:mainfrom
NilayYadav:fix-chat-menus-modal-layer
Sep 7, 2026
Merged

danielhanchen merged 12 commits into
unslothai:mainfrom
NilayYadav:fix-chat-menus-modal-layer

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Opening the sidebar menus, the chat row menu or the project menu locks the whole page while the menu is open. The background cannot be scrolled, the scrollbar disappears and comes back so the layout jumps, and screen readers are told the rest of the app is hidden. The cost grows with the length of the chat, so on a long thread each open is a visible pause. Two menus in the app already avoid this.

This moves eight menus onto the same approach, through one shared component so they cannot drift apart again. The component holds the guard that stops the click which closes a menu from also hitting whatever is under it.

Tested in a browser on both builds. Before, opening any of them locks page scrolling and hides about ten elements from screen readers. After, the page is untouched and every menu still opens.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@NilayYadav

NilayYadav commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions evidence

Reviewed at 0db1ed7bba4e335926647056bfe2b7e90f641fa0, updated for fbb5884a60310d518fb06b0bb89af9ffdb57deda (one more fix, and the merge of upstream main). The defect and the fix are both reproduced on Actions, on fresh upstream main, with one identical Playwright probe on every branch.

The defect, on the merge base

A probe opens every reachable aria-haspopup="menu" trigger on /chat and on a project page and records what the open writes to the document.

  • Merge base b319ba38 — 13/13 menus lock the document: each open sets body{pointer-events:none} and body[data-scroll-locked], and hides 11 more nodes from assistive tech.
  • PR head — 0/13: scoped_locked=0, nothing written to <body>, 0 nodes aria-hidden.

In the same head run, five menus this PR does not touch (Tools and attachments, Permission level for tool calls, the project switcher) still lock the document, so the probe is demonstrably able to see a lock on the branch where the converted ones come back clean.

What that looks like

Sidebar seeded with 60 chats so the list overflows; Chat options opened; one 400px wheel over the sidebar behind the open menu.

  • Merge base: scrolled_px=0. The screenshot after the wheel is byte-identical to the one before it — the page did not move at all.
  • 0db1ed7b: scrolled_px=400, but the menu stayed open — see the P2 below. That screenshot is the left half of the image.
  • f78d4047: the list scrolls 400px and the menu closes with it. Right half.

PR 10262 menu closes when the list behind it scrolls

Findings fixed on this branch

P2 — a menu that outlived its row (f78d4047). Regression introduced by the conversion itself, visible in the earlier version of the screenshot above. Nothing locks scroll behind a non-modal menu, so the list its trigger sits in moves while the menu is open; Radix keeps the content anchored to the trigger and pins it to the viewport edge once the trigger scrolls out. The result was an open Chat options menu, Delete and all, for a row the user could no longer see. NonModalDropdownMenu now closes on any scroll whose target contains the trigger (capture phase on document), so the menu's own viewport and its submenus still scroll freely. Radix's close-time focus return would then scroll the trigger back into view and undo the user's scroll, so a scroll-triggered close keeps focus on the trigger with preventScroll; Escape and item selection keep the normal focus return.

Verified locally with Playwright in Chromium and WebKit (the desktop app's engine), on the merged branch: wheel over the sidebar closes the menu and the list stays where the user put it (4964 -> 5364, no snap-back); a wheel inside the menu or an open Export submenu leaves both open; arrow keys leave it open; a list reflow above the trigger leaves it open; Escape returns focus to the trigger; the first click after a scroll-close is delivered, not swallowed by the dismiss guard.

P2 — the dismiss guard outlived the menu (82a4e774). Also caught independently by Codex. DropdownMenuContent carries data-closed:animate-out ... duration-100, and shadcn/tailwind.css maps data-closed to [data-state="closed"], so Radix Presence holds the content in unmountSuspended until animationend. The mount-scoped MenuDismissGuard therefore kept watching document for ~100ms after the menu had closed, and armed on any press in that window — so the click that followed was swallowed with no menu open. That is reachable through the menus' own items: Rename and Delete open a dialog, and the first click into it lands inside the window.

The same probe, on two branches that differ only by the fix commit, measures it on Actions. It closes a menu, then clicks 30ms later and asks whether the click reaches a bubble-phase document listener — the guard swallows in the capture phase, so a swallowed click never gets there.

before the fix (run) after (run)
content 30ms after close state=closed, animation=exit, 0.1s state=closed, animation=exit, 0.1s
click during that window swallowed (0 -> 0) delivered (0 -> 1)
same click after the window delivered delivered
menus locking the document 0/13 0/13

Both routes, both branches. The control line matters: the identical click lands once the content has unmounted, so the check is measuring the window and not a dead button. The guard is now rendered only while the menu is open; arming still survives the unmount, because arm registers on document — verified all four ways round in a local harness too: dismissing click swallowed, menu closed, next click delivered, click during the exit window delivered.

P3 — the Think effort menu had a modal twin. shared-composer.tsx renders the same control as the converted one in thread.tsx, with the same aria-label and the same data-pill-label, and it was left modal. That is Compare mode, where two threads are mounted at once, so it is the worst place to keep the <body> write. Converted, and the guard test now covers it.

Test. Rewritten onto the TypeScript AST, the way tests/action-menu-modal-layer.test.ts already does it, so it reads the enclosing menu root rather than one exact spelling of <DropdownMenu>, and checks every occurrence of each marker rather than the first.

Not changed

Tools and attachments (thread.tsx), Permission level for tool calls and the project switcher are still modal and still lock the document — measured above. They are pre-existing and out of this PR's scope; Tools and attachments also needs root onOpenChange, which NonModalDropdownMenu does not currently forward. Worth a follow-up.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-07T04:43:54.103475Z 1742281 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 0db1ed7bba

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the sidebar and chat row menus in app-sidebar.tsx are still modal on main, so each open locks background scrolling and hides the rest of the app from assistive tech, and the shared component keeps the eight from drifting apart again. Will get this reviewed.

@Imagineer99 Imagineer99 self-assigned this Sep 4, 2026
@Imagineer99

Copy link
Copy Markdown
Member

Just noting this here since I mentioned it in chat: I reproduced the dropdown positioning issue from the AFTER screenshot with Playwright. If the sidebar is scrolled while the menu is open, the trigger moves off-screen but the menu stays open and gets clipped at the top. Pressing Escape then jumps the sidebar back to the trigger (scrollTop 480 to 0). Reproduced in Chrome, Edge, Chromium, and Firefox.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: f78d404769

ℹ️ 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".

@Imagineer99

Imagineer99 commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Rechecked the latest head fbb5884 with the same Playwright repro and this is fixed now 👍 After a 480px sidebar scroll, the menu closes, scrollTop stays at 480, and Escape no longer snaps it back to 0. Confirmed in WSL Chromium/Firefox and native Windows Chrome/Edge. Thanks!

The AST tests pin which menus use NonModalDropdownMenu. What the wrapper then does is
only answerable in a browser, and it is where this has gone wrong before: a dismissal
deleting a chat message (unslothai#9243), a lost trigger focus (unslothai#9772), a guard that outlived the
exit animation, and a menu left anchored to a row that had scrolled away.

smoke-nonmodal-menus.html mounts the real component on a 60 row overflowing list, with a
submenu, a menu whose own viewport scrolls, an unrelated scroller, and one still-modal
menu as a control. The control is the shape every converted menu had before, so a case
that behaves the same on both is Radix rather than this wrapper, and the lock it still
writes to <body> is what proves the probe can see a lock at all.

34 checks, passing on chromium, firefox and webkit. Frontend CI runs the chromium leg
next to the existing dismiss-guard probe; PW_ENGINE picks the other two.
@danielhanchen
danielhanchen self-requested a review as a code owner September 6, 2026 12:37
Whether the reopening click lands while Radix still has the closing content mounted
is a race, and the converted menu and the unconverted control each win it about as
often on Windows Firefox, which made the comparison red for no defect. Assert the
part that is not a race: neither may end up with two menus open.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd3bc5a622

ℹ️ 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".

return () => document.removeEventListener("scroll", onScroll, { capture: true });
}, [open]);
return (
<DropdownMenu modal={false} open={open} onOpenChange={setOpen}>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear the scroll-close marker when reopening

If a scroll closes the menu and the user reopens it during the 100 ms exit animation, the content never unmounts, so onCloseAutoFocus does not run and closedByScroll.current remains true. Dismissing that reopened menu by clicking an input then incorrectly follows the scroll-close path and focuses the trigger, stealing focus and the caret from the input. Clear the marker when onOpenChange transitions back to open rather than relying solely on the eventual close-autofocus callback.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to reproduce this and could not: the precondition is unreachable. Reopening a menu while its closing content is still mounted does not work on any engine, because the press lands on a DismissableLayer that is still there and closes it again. Swept the delay between the scroll-close and the reopening click, reading [data-slot=dropdown-menu-content] at the moment of the click:

delay content at click reopened
0 to 80ms present, data-state=closed no, on all three engines
100ms present on chromium and firefox, gone by the time the click lands yes on chromium and firefox, no on webkit
150ms and up gone yes on all three

So the reopen only lands once the content has unmounted, and unmount is exactly when onCloseAutoFocus runs and clears closedByScroll. There is no window where the flag survives into a later close. The wrapper also exposes no root level open, so a caller cannot reopen it by another route.

The downstream symptom is covered either way: a scroll-close does not change how the next Escape restores focus in tests/studio/playwright_nonmodal_menus.py passes on chromium, firefox and webkit.

Two things the driver needed and did not have. tests/studio/playwright_nonmodal_menus.py
was missing from the workflow's pull_request paths, where every other driver this job
invokes is listed, so a PR touching only the harness would never run it. And its report
was not in the failure upload, which test_every_smoke_report_is_covered_by_the_failure_upload
rejects by design, so the required workflow-trigger-lint job was red.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 7, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 7, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 5f75f276c5

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

Converged. Codex approved 5f75f276c, which is head, with no open items.

Two of its three items on my commits were right and are fixed in 5f75f276c: tests/studio/playwright_nonmodal_menus.py was missing from this workflow's pull_request paths, and its report was missing from the failure upload, which test_every_smoke_report_is_covered_by_the_failure_upload rejects by design. That second one had the required workflow-trigger-lint job genuinely red, so thanks for it. The third, a closedByScroll marker surviving a reopen during the exit animation, I could not reproduce and have answered inline with the measurement: the reopen only lands once the content has unmounted, and unmount is when onCloseAutoFocus runs and clears the marker.

The one red check on this PR is not this PR. Frontend unit tests (Windows) fails on smoke-composer-icons.html must load /crypto-boot.js. That page came from #10407 and is the only HTML entry without the tag; tests/crypto-uuid-boot.test.ts enumerates the entries rather than a fixed list, so it fails on a clean checkout of main with nothing else applied. I reproduced it there and opened #10413 with the one line fix. Once that lands this check goes green here without a rebase.

Cross-OS re-run on the current head is green again, all nine cells, after one unrelated flake on macOS (anthropic-dated-model-ids-reach-the-picker) that passed on re-run.

tests/studio/test_click_forced.py rejects a forced click that does not scroll
first, and it is right to: force turns the scroll off and Playwright will not
click a point it cannot reach. The sanctioned helper scrolls into view, which is
the one thing this case must not do, since it is about a trigger the scroller
clips. A real pointer press on the intersection of the trigger and the scroller
keeps the case and needs no force at all. Still 34/34 on chromium, firefox and
webkit.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…closed

The content is held mounted for its exit animation, so a scroll close can be
followed by a click into an input before onCloseAutoFocus runs. Radix's own
restore checks for that interaction, but the scroll-close path calls
preventDefault, which skips the check, so the trigger pulled the caret straight
back out of the input. Measured on chromium, firefox and webkit: with the menu
scroll-closed and the input clicked 0 to 90ms later, focus ended on the trigger
every time, against the input on an ordinary close.

Make the same check before taking focus. The case the path exists for is
unchanged: with nothing else claiming focus, a scroll close still lands on the
trigger and still keeps the scroll, 600px in all three engines.

The regression case fails without this and passes with it.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 174228178f

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@danielhanchen
danielhanchen merged commit b48b602 into unslothai:main Sep 7, 2026
30 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants