Repository navigation
[navigation menu] Fix interaction, value, and styling-hook bugs - #4942
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,218.24 ms -48.64 ms(-3.8%) | Renders: 50 (+0) | Paint: 1,847.66 ms -62.11 ms(-3.3%) No significant changes — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
7f8bb7f to
3ae7143
Compare
flaviendelangle
left a comment
There was a problem hiding this comment.
PR Review Summary — #4942 [navigation menu] Fix interaction, value, and styling-hook bugs
Branch: codex/navigation-menu-sweep (5 nav-menu commits, 12 files, +324/−28)
Reviewers: code-reviewer · pr-test-analyzer · silent-failure-hunter · comment-analyzer
Verdict: Fixes are sound; the gaps are almost entirely in test coverage.
Critical Issues (0 found)
None. The four claimed fixes (disabled-trigger guards, onValueChange dedup, falsy item values, actionsRef.unmount()) all hold up under inspection, and no silent failures, swallowed errors, or improper fallbacks were introduced.
Important Issues (5 found — all in test coverage)
-
Disabled-trigger touch path uncovered —
NavigationMenuRoot.test.tsx:1820-1866
The source guard atNavigationMenuTrigger.tsx:700-702covers all pointer types, but the suite only exercises mouse/keyboard. Add apointerDown/pointerUpwithpointerType: 'touch'(pattern at:1188-1262). -
Falsy value coverage incomplete —
NavigationMenuRoot.test.tsx:1587-1618,2637-2656
Onlyvalue={0}is tested, but the predicate change atNavigationMenuRoot.tsx:157,169,178applies equally to''andfalse. Parametrize with all three (it.each). -
Duplicate
onValueChangetest doesn't faithfully traverse —NavigationMenuRoot.test.tsx:1561-1585
The test programmatically focusestrigger2before pressingArrowDown, so the listNavigation traversal path the guard atNavigationMenuTrigger.tsx:663actually targets isn't exercised. Use realArrowRight/ArrowLeftacross triggers with the popup open. -
actionsRef.unmount()not exercised mid-transition or while open —NavigationMenuRoot.test.tsx:1868-1894
The test only callsunmount()after a clean close. The very scenario that justifies the API — unmount while open or mid-animation — isn't covered. -
side="left"test is layout-dependent in jsdom —NavigationMenuRoot.test.tsx:1896-1925
Without real bounding rects,useAnchorPositioningmay resolve to its default side, silently passing the negative case. Either wrap withdescribe.skipIf(isJSDOM)or assert viadata-side="left". RTLinline-start/inline-endbranch atNavigationMenuPopup.tsx:49-53is also entirely untested.
Suggestions (6 found)
-
Hover test uses
fireEvent.mouseEnterinstead ofpointerEnter—NavigationMenuRoot.test.tsx:1821-1834
useHoverFloatingInteractionrequirespointerEnterwithpointerType: 'mouse'(pattern at:1192,1222). Current test likely passes only becausedisabledshort-circuitsinteractionsEnabled, not because the hover code path runs. -
"Suppress initial open transitions" undertested —
NavigationMenuRoot.test.tsx:1507-1540
Assertstransition: 'none'immediately after click but never asserts it's cleared on a subsequent tick. A regression that pinsinstant: trueforever would pass. -
Nested falsy
setValue(null)propagation untested —NavigationMenuRoot.tsx:177-184
New nested branch usingnextValue == nullhas no regression test. -
Positioner resize-listener re-subscription is fragile —
NavigationMenuPositioner.tsx:139-162
Addinginstantto deps causes the resize listener to unsubscribe/re-subscribe on every flip. Works only becausehandleResizedoesflushSync(setInstant(true))beforeinstantTimeout.start(100, …). Either add a comment explaining the ordering invariant, or split the effects. -
Three comment-clarity nits
NavigationMenuRoot.tsx:214—useImperativeHandleforactionsRefis silent about the contract that consumer opt-in disables auto-unmount viaenabled: !actionsRefon bothuseOpenChangeCompletecalls. One line of "why" warranted.NavigationMenuTrigger.tsx:661-663— comment citesonKeyDownbut the guard sits insidehandleActivation; clarify.NavigationMenuList.tsx:99-101— comment about "skipping the onKeyDown handler" describes work done earlier at line 72, not here.
-
Public docs likely need regeneration —
docs/src/app/(docs)/react/components/page.mdx:1102
The Trigger prop list does not includedisabled. This PR is the first that makesdisabledmaterially observable on the Trigger. Runpnpm docs:apito regenerate.
Strengths
- All four claimed fixes verified correct;
nextValue == nullreplaces!nextValueconsistently in every site (Root lines 157, 169, 178), and the trigger-side guards (NavigationMenuList.tsx:44-46,NavigationMenuTrigger.tsx:130-132) mirror that. - Disabled-trigger guard is layered correctly:
&& !disabledon the interaction hooks, an early-return inhandleOpenEvent, anduseButton's own keyboard short-circuit one layer down. actionsRefwiring is null-safe (no error swallowing inhandleUnmount).- New
data-attributefiles (anchorHiddenon Popup,popupOpenon Icon, typedactivationDirection) are accurately wired and matchtypes.md+page.mdx. - Tests use
vi.fn()with call-count assertions,flushMicrotasks(), andawait act(...)deterministically. - No
window.setTimeout,requestAnimationFrame, rawdocument/window, orReact.useLayoutEffectwere introduced — AGENTS.md guidelines followed.
Recommended Action
- Tests are the only blocker. Add coverage for items 1–5 before merging — they're the meaningful regressions a future change could re-introduce undetected.
- Apply comment clarifications (item 10) and run
pnpm docs:api(item 11) — both are mechanical. - Address suggestions 6–9 opportunistically.
3ae7143 to
eaff629
Compare
8b1a9b2 to
0b15844
Compare
24cb3c2 to
0d2db2c
Compare
This is part of the Codex sweep for Navigation Menu. It restores the local fixes from the recovered branch while preserving newer upstream changes.
Changes
onValueChangecalls when switching items via keyboard.actionsRef.unmount()action.Original findings addressed