Repository navigation
[menu] Preserve dialog focus on pointer leave - #4581
Conversation
commit: |
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
a2d4109 to
a495dde
Compare
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codex Review (GPT-5.4)Reviewed the full branch against a freshly fetched 1. Bugs / Issues (None)I did not find any branch-relevant correctness, regression, typing, or repo-convention issues in the patch. Root Cause & Patch AssessmentReturning a per-request canceler from Test Coverage AssessmentThe added regressions cover both halves of the bug: canceling stale pending item focus in RecommendationApprove ✅ The fix matches the reported failure mode, stays local to the focus-queue bug, and the targeted Chromium coverage meaningfully reduces regression risk for the affected interaction path. |
flaviendelangle
left a comment
There was a problem hiding this comment.
PR #4581 Review — [menu] Preserve dialog focus on pointer leave
Context
The user asked me to run the PR review skill on #4581, dispatching multiple agents to hunt for regressions, then print the consolidated report to an MD file.
PR #4581 is a focused 5-file fix (281 additions / 4 deletions) by @atomiks. It addresses a bug where pointerleave on a menu item was clearing the shared module-level rAF used by enqueueFocus, which canceled the dialog's pending initial focus when a Dialog opened from a Menu.Item (via Dialog.Trigger composition). The fix returns a per-rAF canceler from enqueueFocus and uses it locally in useListNavigation instead of the global cancel.
I dispatched three parallel regression-hunting agents:
- enqueueFocus refactor auditor — checked all
enqueueFocuscall sites (useListNavigation.ts,FloatingFocusManager.tsx×3) for behavioral changes. - useListNavigation pointer-logic auditor — checked the new pointerleave/cancel flow, ordering, race conditions, sync path, unmount safety.
- Test coverage and consumer impact auditor — checked which other components compose list-nav with overlay triggers, and assessed test quality.
Plan
Write a single consolidated review report at /tmp/pr-4581-review.md based on the agents' findings, organized as:
- TL;DR verdict
- What the PR changes
- Critical regressions (none)
- Coverage gaps and missing tests (the actionable stuff)
- Verified-safe areas
- Recommendations to the author
Key findings (preview)
Verdict: APPROVE with minor coverage suggestions
No critical regressions identified. The fix is correct, narrowly scoped, and addresses the root cause (shared module-level rafId cross-talk between useListNavigation and FloatingFocusManager).
Critical regressions
None.
Highest-value coverage gaps (actionable)
- Combobox / Autocomplete are affected but untested.
packages/react/src/combobox/root/AriaCombobox.tsx:1041passesfocusItemOnHover: highlightItemOnHoverintouseListNavigation, so the same cross-talk bug can hit aCombobox.Itemrendered as aDialog.Trigger/Popover.Trigger. Zero Dialog/Popover references inComboboxRoot.test.tsx. - Menubar is affected.
packages/react/src/menubar/Menubar.tsx:94forwardshighlightItemOnHover={hasSubmenuOpen}. Untested. - ContextMenu (built on
MenuRoot) is affected and not tested for this path. - The new useListNavigation test is weak.
useListNavigation.test.tsx:689-744only asserts pointerleave still clears item focus — it does not demonstrate the cross-talk fix because there is no competing focus request. Reverting the fix would still pass it. The test exercises the code path, not the behavior the PR claims. - The MenuRoot test is genuinely behavioral.
MenuRoot.test.tsx:859-937installs rAF mocks betweenclick(dialogTrigger)andpointerLeaveso both the list-nav item focus andFloatingFocusManager's dialog focus (FloatingFocusManager.tsx:748) land in the same mocked frame map. Reverting the fix would make this test fail. ✅
Verified safe
- Three
enqueueFocuscallers inFloatingFocusManager.tsx(lines 748, 954, 974) discard the new return value cleanly — no type/lint impact. - The canceler's
if (rafId === currentRafId)guard correctly makes a stale canceler a no-op when a laterenqueueFocussuperseded it. - Sync path (
forceSyncFocusRef.current === true) returnsNOOPand is handled correctly: focus already happened, nothing to cancel. - Race condition
pointerleave(A) → pointermove(B):cancelQueuedFocusRef.currentis overwritten before any subsequent pointerleave can fire a stale canceler. - Combobox uses
virtual: true, so itsrunFocusnever touchescancelQueuedFocusRef— pointerleave's?.()is a no-op (identical to old behavior). Selectis not affected:SelectRoot.tsx:363setsfocusItemOnHover: false.NavigationMenudoes not useuseListNavigation— exempt.- Order of operations in
onPointerLeave(cancel →indexRef = -1→onNavigate(event)→ conditional floating refocus) is preserved. - No reviewer concerns in the PR thread (only an automated Codex review approving).
Pre-existing (not a regression, worth noting)
focusItem's outerrequestAnimationFramefor scroll-into-view (useListNavigation.ts:335-357) is not captured by any canceler. Pre-existing; the PR doesn't change it.- No unmount cleanup for
cancelQueuedFocusRef. A pending rAF will still callel?.focus()on a possibly detached node (no-op). Pre-existing.
Recommendations to author
- (P1) Strengthen
useListNavigation.test.tsxtest: add a competing focus request (e.g., aFloatingFocusManagerinitial focus) that would be canceled by the old globalrafIdpath, so the test would actually fail if the fix were reverted. - (P2) Add a regression test for
Combobox.Itemrendered asDialog.Trigger(and/orPopover.Trigger) — same pattern as the newMenuRoottest. - (P3) Consider documenting why
focusItem's outer scroll-into-view rAF remains uncanceled (or capture it too). - (P3) Optionally add a docs example showing the supported
Menu.Item+Dialog.Triggercomposition pattern (none currently exists indocs/src/app/(docs)/react/components/menu/).
Pointerleave was clearing the shared queued focus request while a dialog opened from a menu item was still waiting for its initial focus to land. This keeps list navigation's stale item-focus cancellation local to the request it owns, so it no longer cancels a later dialog focus request while preserving the existing global focus ordering for menu item navigation.
Changes
enqueueFocus()for the specific scheduled focus frame.