Repository navigation
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,020.63 ms +19.33 ms(+1.9%) | Renders: 76 (+0) | Paint: 1,643.38 ms +35.31 ms(+2.2%)
14 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
|
@claude review |
PR reviewThe fix is narrowly scoped, Bugs (1)1. 🟠 Touch-originated
|
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
A mouse right-click and a touch long-press both produce a `contextmenu` / `TouchEvent` with `detail === 0`, which the shared Menu logic classified as a keyboard activation, adding `data-instant="click"` to the popup. Consumers of `data-instant:transition-none` then skipped the enter transition while a later mouse close still played the exit transition. The trigger now classifies the gesture itself and passes an explicit `instantType` on the event details (touch and pointer animate; a keyboard `contextmenu` stays instant). A pending long-press recorded by `handleTouchStart` marks the Android native `contextmenu` as pointer-driven, resolving the open-path race. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
3a90588 to
7accb92
Compare
|
@claude review |
PR reviewThe fix is well-targeted — right-click and long-press opens no longer inherit the Bugs (1)1. 🟠 The non-Chromium keyboard fallback assumes zeroed coordinates, which Firefox/Safari likely do not provideLocation: function isKeyboardContextMenu(event: MouseEvent): boolean {
const { pointerType } = event as PointerEvent;
if (pointerType != null) {
return pointerType === '';
}
return event.button === 0 && event.clientX === 0 && event.clientY === 0;
}The Chromium branch is sound. The fallback — used by Firefox and Safari, which still dispatch This repo already has a cross-browser answer to exactly this problem, and the header comment on it names the same two browsers: // packages/utils/src/useEnhancedClickHandler.ts
// Safari and Firefox do not provide the PointerEvent to the click handler (they use MouseEvent) yet.
lastClickInteractionTypeRef.current = event.pointerType as InteractionType;Failure scenario: A user focuses a Fix: Track the last Tests (1)1. 🟠 No test exercises the
|
…vent shape Chromium dispatches `contextmenu` as a `PointerEvent`, so `pointerType` answers whether a pointer opened the menu. Firefox and Safari still dispatch a plain `MouseEvent`, and the previous fallback inferred keyboard activation from zeroed coordinates -- but Gecko and WebKit position a keyboard-invoked native menu against the focused element, so those coordinates are real and a Shift+F10 open would have been misread as pointer-driven. Follow the gesture that produced the event instead: a pointer-driven `contextmenu` always begins with `pointerdown` on the trigger, while a keyboard one is always generated by the keypress whose `keydown` fires first and clears the recorded gesture. This also subsumes the Android long-press special case, since a long press records a `touch` pointerdown before the native `contextmenu`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Address review feedback on the gesture-classification approach: - Move the trigger's classification off the public event details and onto the Context Menu root context. `createChangeEventDetails` spreads custom properties onto the object passed to `onOpenChange`, so `instantType` was reaching consumers as an undocumented key, with producer and consumer agreeing only via a string literal and a cast. It is now a typed ref on `ContextMenuRootContext`, alongside the other trigger-to-root refs, and `MenuRoot` reads it only for a `triggerPress` open whose parent is a context menu. - Treat the secondary button on the `contextmenu` as a positive pointer signal. The recorded gesture is best-effort, and a right-click whose `pointerdown` never reached the trigger was falling through to the keyboard branch. - Record the gesture in the capture phase so a descendant that stops `pointerdown` propagation (drag handles, editor widgets) cannot hide it. - Drop the unreachable `!isTouchEvent` guard: `keyboardActivation` is only ever true on the `contextmenu` path. Tests cover a right-click with no preceding `pointerdown`, a Ctrl+click whose `pointerdown` a descendant swallows, and a pointer gesture following a key press; each fails without the specific mechanism it pins. The pointer helpers drop `firePointer`, whose `timeStamp` precondition nothing here reads. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The previous code claimed Chromium reports an empty `pointerType` for a keyboard `contextmenu`. Measured on Chromium 151, it does not -- Shift+F10 and the Menu key both report `pointerType: 'mouse'`, the same value a right-click reports: shift+F10 PointerEvent pointerType="mouse" button=-1 detail=0 ContextMenu key PointerEvent pointerType="mouse" button=-1 detail=0 right-click PointerEvent pointerType="mouse" button= 2 detail=0 So that branch classified every keyboard open in Chrome and Edge as a pointer open, dropping `data-instant` and animating a popup that should have appeared instantly. The coordinates are no better: a keyboard activation carries the focused element's box, in Chromium as well as Gecko and WebKit. Drop the branch. What is left is engine-agnostic and holds by measurement: the secondary button is a positive pointer signal, and otherwise the answer is whether a pointer gesture is in flight. The ordering that supports it: shift+F10 -> keydown -> contextmenu(button=-1) right-click -> pointerdown -> contextmenu(button=2) ctrl+click -> keydown(Control) -> pointerdown -> contextmenu Ctrl+click records its gesture after the modifier's key press clears it, so it still classifies as a pointer. The two browser-only tests now reproduce the measured Chromium event shape rather than one Chromium never emits; the keyboard case fails against the old branch. `MenuRoot` also consumes the ref it reads, so a stale value cannot suppress a later open that never wrote one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The gesture-classification comments had grown into multi-paragraph blocks with bullet lists, which nothing else in these files does -- the neighbouring comments are one or two plain lines explaining a single non-obvious "why", and the sibling context fields carry none at all. Keep the facts that are not recoverable from the code (that the event's own shape cannot identify a keyboard `contextmenu`, and that the recording is taken in the capture phase) and drop the narrative around them. Comments only; no behaviour change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
@claude review |
PR reviewThe fix is sound in shape — moving gesture classification into Bugs (1)1. 🟠 A touch long press with no
|
There was a problem hiding this comment.
🔵 Needs a closer look
Two moderate gesture-tracking issues remain unresolved in ContextMenuTrigger.
Pull request overview
Fixes incorrect data-instant="click" behavior for pointer- and touch-driven context-menu openings.
Changes:
- Tracks context-menu gesture metadata.
- Updates
MenuRootto use the recorded gesture. - Adds interaction-specific regression tests.
File summaries
| File | Summary |
|---|---|
packages/react/src/menu/root/MenuRoot.tsx |
Consumes context-menu gesture metadata when setting instantType. |
packages/react/src/context-menu/trigger/ContextMenuTrigger.tsx |
Classifies pointer, touch, and keyboard context-menu gestures. |
packages/react/src/context-menu/trigger/ContextMenuTrigger.test.tsx |
Tests long-press behavior. |
packages/react/src/context-menu/root/ContextMenuRootContext.ts |
Exposes gesture metadata through context. |
packages/react/src/context-menu/root/ContextMenuRoot.tsx |
Initializes and provides the metadata ref. |
packages/react/src/context-menu/root/ContextMenuRoot.test.tsx |
Tests gesture classification across platforms. |
Review details
Suppressed comments (2)
packages/react/src/context-menu/trigger/ContextMenuTrigger.tsx:242
- The trigger also supports the
TouchEventpath, butlastPointerTypeRefis only populated byonPointerDownCapture. On a browser that deliverstouchstart/nativecontextmenuwithout Pointer Events, the native menu event can arrive before the 500 ms timer, leaving this ref empty and causingisKeyboardContextMenuto classify the touch open as keyboard (data-instant="click"). Record the touch gesture when a single touch starts so the native-contextmenu race is covered on that path too.
onPointerDownCapture: handlePointerDown,
onKeyDownCapture: handleKeyDown,
packages/react/src/context-menu/trigger/ContextMenuTrigger.tsx:110
lastPointerTypeRefis never consumed or reset after this classification. After any pointer-driven context menu, a later keyboard or assistive-technologycontextmenuthat does not dispatch akeydownwill reuse the stale'mouse'/'touch'value and incorrectly omitdata-instant="click". Clear the recorded gesture after computing the activation type (and cover this sequence with a regression test).
handleLongPress(
event.clientX,
event.clientY,
event.nativeEvent,
isKeyboardContextMenu(event.nativeEvent, lastPointerTypeRef.current),
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
This pull request has been inactive for 30 days. Please remove the stale label or leave a comment to keep it open. Otherwise, it will be closed in 15 days. |
closes #5593
Right-click and touch long-press both produce
detail === 0, so MenuRoot classified them as keyboard clicks and putdata-instant="click"on the popup. Anyone usingdata-instant:transition-nonelost the enter transition while the exit one still played.ContextMenuTrigger now tags the event details with the gesture it actually handled instead of MenuRoot guessing from the event shape. Also covers the Android case where the native
contextmenuand our long-press timer race to open the menu.