Repository navigation
studio: stop a menu dismissal deleting a chat message - #9243
Conversation
|
@codex review |
|
Frontend unit tests (Windows) is red on one test that this branch does not touch:
It arrived with #9173. Leaving it alone rather than folding an unrelated fix into this PR, but happy to send it separately. The first Windows run also failed the new guard sweep, which was mine: |
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
1 similar comment
|
@codex review |
|
@codex review |
|
Confirmed this hits the path in studio/frontend/src/components/assistant-ui/thread.tsx where the non-modal More menu sits beside an unconfirmed Delete message on line 7034, so a dismissing press can still remove a message. Could you get the Frontend build and bundle sanity job green so I can review it properly? |
|
@codex review |
c638b26 to
a090b7b
Compare
|
@codex review |
|
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ec0d5f140
ℹ️ 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".
| export function useDismissingClickGuard(): void { | ||
| useEffect(installDismissingClickGuard, []); |
There was a problem hiding this comment.
Stop guarding as soon as the menu closes
When an item closes the menu, Radix Presence can keep the content—and therefore this effect—mounted during its exit animation. A click during that interval is unrelated to any open menu, but onPointerDown still arms swallowClick, causing the click to be discarded. The newly added select_then_quick_click probe documents that the current action-menu content remains mounted for roughly 126 ms and deliberately clicks after 40 ms, so this also makes the new CI probe fail; drive the guard from the menu's open state rather than the content's mount lifetime.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejected on exact head: this content has no exit animation, Radix unmounts immediately when animationName is none, and select_then_quick_click returned neutralClicks=1 on Chromium, WebKit, and Firefox. The probe comments describe a class this menu does not have.
|
Codex Review: Didn't find any major issues. Hooray! 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". |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f28d94e68a
ℹ️ 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".
| if (isActivationKey(event)) { | ||
| activationKeyIsDown = true; | ||
| return; |
There was a problem hiding this comment.
Disarm when Space starts a new gesture
When the dismissing press produces no click—for example, pointerdown/up on a disabled native composer control—the guard remains armed for 500 ms after pointerup. If the user presses Space during that window, this branch marks it as part of the old gesture even though the guarded pointer is no longer down; the button's keyup-generated click fires before the zero-delay disarm timer and is swallowed. This prevents a distinct keyboard action, such as using Space on the still-focused More trigger to reopen the menu, so Space keydown should disarm when pointerIsDown is already false while preserving the held-Space-before-pointerup case.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejected after strict product-path validation on exact head 6155946. In the real Studio heavy-thread UI, the Search pill was put in the same native disabled state and tested in Chromium, Firefox, and WebKit with the menu opened by both mouse and keyboard. The disabled press emitted no click, but activeElement became BODY in all six runs; Space then targeted BODY and produced no activation click to swallow. When More was artificially refocused, Radix reopened the menu on keydown and this guard did not prevent it. The synthetic failing sequence manually dispatches a detail=0 click without a focused activatable control, which browsers do not synthesize. No legitimate production path reproduced, so no code change is warranted.
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
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.
#10262) * Studio: take the chat and sidebar menus off the body modal layer * Studio: gate the menu dismiss guard on the open state * Studio: check every occurrence of each menu marker * Studio: close a non-modal menu when the list behind it scrolls * Studio: cover the non-modal dropdown wrapper in a browser 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 (#9243), a lost trigger focus (#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. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Hold the invariant, not the race, when a menu is reopened mid-animation 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. * Tighten the comments this branch adds Comments only, no code. The paragraphs that restated the code are gone and the rest collapse to a line each. Every fact that names a defect somebody could reintroduce is kept, which is what keeps this a modest sweep rather than a large one. * Wire the new browser check into the paths filter and the failure upload 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. * Press the visible sliver instead of forcing the click 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. * Do not take focus back from whatever the user clicked while the menu 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. --------- Co-authored-by: danielhanchen <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
The bug
Dismissing the chat action bar's "More" menu can delete a message, with no confirmation.
#8992 set
modal={false}onActionBarMorePrimitive.Rootinstudio/frontend/src/components/assistant-ui/thread.tsx. That was the right call and this PR keeps it: a modal Radix layer parkspointer-events: noneon<body>, which is an inherited property, so every open invalidates computed style for the whole thread.studio/frontend/tests/action-menu-modal-layer.test.tspins the menu non-modal and carries the numbers.What that shield was also doing is absorbing the press that dismisses the menu. Radix's outside handler closes the layer but never cancels the event, so one press on a control beside the menu both closes it and fires that control. Two buttons from the trigger sits
DeleteMessageButton(thread.tsx:7033), which deletes ononClickwith no confirmation.Measured with
tests/studio/probe_dismiss_guard.pyagainst a seeded thread of 10 assistant messages:origin/main(6e5360c)The gestures that reach it include a quick click, a press held past any fixed deadline, a press while the main thread is busy, a touch tap, a press with a modifier, Enter or Space pressed mid-press, and Space pressed after the menu was already dismissed.
The fix
studio/frontend/src/lib/menu-dismiss.tsswallows exactly the click that dismissed the menu.It arms from
pointerdownondocumentin the capture phase, not from Radix'sonPointerDownOutside. Two reasons, both measured rather than assumed. A guard armed from that callback and retired by a fixed timer is gone before the browser synthesisesclickon release, and a press can be held for as long as the user likes. AndusePointerDownOutsidein@radix-ui/react-dismissable-layer1.1.11 defers to the resultingclickforpointerType === "touch", listening onownerDocumentin the bubble phase, while React 19 delegates to the root container insidedocument, so the control's ownonClickhas already run by the time Radix calls back.The upper bound is anchored at
pointerup, not at the press, so a gesture that never becomes a click cannot leave the swallower waiting for an unrelated one. A non-primary button never arms it at all, since a right click raisescontextmenuand noclick.Throwing the click away is only half of undoing the press. The press also focuses what it landed on, and a focused button is one Space away from firing, so the swallow releases the focus it took unless the target takes text.
studio/frontend/src/lib/menu-dismiss-guard.tsxexposes<MenuDismissGuard />, mounted insideActionBarMorePrimitive.Content. Radix mounts content on open and unmounts it on close, so the guard's lifetime is the menu's with noonOpenChangewiring.The sidebar's "More" destinations flyout stays non-modal and unguarded. It opens on pointer enter, so an unconditional swallow there would eat an ordinary click on the nav row the pointer was heading for.
nonmodal-menu-dismiss-guard.test.tsrecords that as an explicit exception and fails on any other unguardedmodal={false}menu.Before and after
Same fixture, same viewport, same gesture: open the last reply's "More" menu, press and hold its "Delete message" button for 600ms, release. Captured at 6e5360c and at this branch's head.
On
main, reply 9 is gone and the thread ends at the prompt that produced it:On this branch the menu closes and the reply is still there:
Tests
tests/studio/probe_dismiss_guard.pydrives the real menu on the heavy-thread smoke page through 19 cases and is wired intostudio-frontend-ci.ymlas a gate. It watches both directions: the dismissing press must not reach the control underneath, and a click inside the menu, a second click after a dismissal, and the click after a right-click dismissal must all still land.nonmodal-menu-second-pointer.test.tsdrives the arm/disarm state machine against a fake document, where the clock can be advanced by hand rather than slept through.nonmodal-menu-dismiss-guard.test.tssweeps every.tsxundersrc/formodal={false}and requires the guard or a listed exception.Checks
probe_dismiss_guard.py: passes on chromium and webkit, fails on both at the merge basenpm test: 3800 of 3801. The one failure,queued-model-capabilities.test.ts, is pre-existing onmain(image-input-support.ts:7imports./mmproj-fallbackwithout an extension)npm run typecheck,npm run build,npm run bundle:check: clean, and the bundle stays within budgeteslint: no new findings, the 55 inthread.tsxandapp-sidebar.tsxare unchanged frommainruff check,ruff format,biome checkon the new files: cleanheld_entercase