Skip to content

[menu] Cancel stale submenu hover-open when Chrome drops mouseleave - #5153

Merged
atomiks merged 6 commits into
mui:masterfrom
atomiks:claude/lucid-lehmann-a04849
Jul 6, 2026
Merged

atomiks merged 6 commits into
mui:masterfrom
atomiks:claude/lucid-lehmann-a04849

Conversation

@atomiks

@atomiks atomiks commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes a Chrome regression where sweeping the pointer quickly across adjacent submenu triggers leaves a submenu stuck open and the parent menu unresponsive. Firefox and Safari are unaffected, and it reproduces on old Base UI versions (e.g. 1.3.0), confirming a browser-side change rather than our code.

Root cause

Each Menu.SubmenuTrigger arms a delayed hover-open on mouseenter and cancels it on the trigger's mouseleave. During a fast sweep, recent Chrome drops the trigger's non-bubbling mouseleave (the synthesized boundary event), so the delayed open is never cancelled and fires for a trigger the pointer has already left. That stale open takes over the currently-hovered item and leaves the parent scope's safePolygon pointer-events: none shielding in place, so the menu appears stuck.

The specific trigger is a common highlight pattern — the hovered item becomes a position: relative stacking context with an absolutely-positioned ::before — which restructures the item's paint box on every hover and trips Chrome's mouseleave synthesis. The bubbling mouseout survives the same crossing.

Fix

Add an opt-in guardStaleOpen to useHoverReferenceInteraction that also cancels a pending hover-open from the trigger's mouseout (when the pointer genuinely leaves, i.e. relatedTarget is outside the trigger), not just from its mouseleave. Because mouseout bubbles and isn't dropped, the stale open is cancelled at the source and never fires. Menu.SubmenuTrigger opts in — tooltips, navigation menu, popover, preview card, etc. are unaffected because the flag defaults to false.

This targets the root cause (the un-cancelled open) rather than the visible symptom, is independent of whatever CSS provokes Chrome's drop, and — unlike a :hover-based guard — is exercisable with synthetic events, so it ships with a regression test (fireEvent.mouseOut on a submenu trigger; verified to fail without the fix).

Closes #5152

@atomiks atomiks added component: menu Changes related to the menu component. type: bug It doesn't behave as expected. labels Jul 1, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5153
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5153
    

commit: 1ef904c

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+190B(+0.04%) 🔺+57B(+0.04%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 1ef904c
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a4bb72da844bd0008bbeab9
😎 Deploy Preview https://deploy-preview-5153--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the claude/lucid-lehmann-a04849 branch from adbf2bb to 1801548 Compare July 1, 2026 11:46
Recent Chrome drops a submenu trigger's non-bubbling `mouseleave` when the
pointer sweeps quickly across adjacent triggers, so the trigger's delayed
hover-open is never cancelled and a stale submenu opens for a trigger the
pointer has already left. The parent menu's safePolygon `pointer-events: none`
shielding is then left in place, so the menu appears stuck open and
unresponsive. Firefox and Safari are unaffected, and it reproduces on old Base
UI versions, confirming a browser-side change rather than our code.

The bubbling `mouseout` survives the drop, so use it as a backup: an opt-in
`guardStaleOpen` on the hover interaction also cancels a pending hover-open from
the trigger's `mouseout` (when the pointer genuinely leaves), not just from its
`mouseleave`. Enabled only for submenu triggers, so tooltips and other hover
consumers are unaffected. See mui#5152.
@atomiks
atomiks force-pushed the claude/lucid-lehmann-a04849 branch from 1801548 to ac3a348 Compare July 1, 2026 13:31
@atomiks atomiks changed the title [menu] Work around Chrome dropping mouseleave during fast submenu sweeps [menu] Cancel stale submenu hover-open when Chrome drops mouseleave Jul 1, 2026
@atomiks
atomiks marked this pull request as ready for review July 1, 2026 23:54

@flaviendelangle flaviendelangle left a comment

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.

PR review

Fixes a real Chrome regression (#5152) where a fast pointer sweep across adjacent submenu triggers strands a stale hover-open. The fix is narrow and correct: an opt-in guardStaleOpen that cancels the pending open from the bubbling mouseout (which Chrome doesn't drop), defaulting to false so only Menu.SubmenuTrigger is affected. Nothing is merge-blocking. I verified the new jsdom tests pass (159 passing in MenuRoot.test.tsx, incl. the 2 new ones) and traced the interaction with the existing open/close paths.

Bugs (0)

No findings.

I specifically checked the highest-risk interaction — that clearing openChangeTimeout from onMouseOut could cancel a legitimately-scheduled submenu close. It does not: Menu.SubmenuTrigger always passes handleClose: safePolygon(...), so on leave onMouseLeave installs the document mousemove handler and schedules the close later via that handler's onClose → closeWithDelay, not synchronously during the leave crossing. onMouseOut neither removes that handler nor races the not-yet-scheduled close, so the browser ordering of mouseout vs mouseleave is immaterial here. The contains(trigger, relatedTarget) guard correctly returns false for relatedTarget === null (leave to nothing) via the contains null-check, and true for within-subtree crossings, matching the two tests.

Tests (0)

No findings.

The two added tests pin the guard's two branches (cancel on genuine leave; keep on within-subtree crossing) with synthetic events, which is the correct level given the real Chrome drop can't be reproduced synthetically. The relatedTarget: submenuTrigger case in the second test exercises the contains(trigger, trigger) === true self-containment path. Normal browser open/close flows remain covered by the existing describe.skipIf(isJSDOM) suites.

Simplifications (0)

No findings.

Docs (0)

No findings. The JSDoc on guardStaleOpen and the two inline comments accurately describe the mechanism and its single-trigger-root intent (each Menu.SubmenuRoot has exactly one trigger, so the "cancels even for sibling triggers" caveat is safe here).

Verdict

Approve — a correctly-scoped, tested fix for a confirmed browser regression with no behavioral risk to other consumers (flag defaults to false). One benign asymmetry worth noting for future readers: unlike onMouseLeave, onMouseOut has no isClickLikeOpenEvent() early-return and clears the timeouts unconditionally — harmless because a click-opened submenu has no pending hover-open or rest timeout to clear, but a one-liner if you want the two handlers to read symmetrically.


🤖 Review generated with Claude Code

@atomiks

atomiks commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Still an issue in v150, so this bug will probably stick around — merging

Document that guardStaleOpen is a mui#5152 regression workaround and only safe on single-trigger, hover-driven roots; it skips the click-like and enabled-sibling-trigger checks mouseleave applies.
@atomiks
atomiks merged commit ad1746b into mui:master Jul 6, 2026
6 checks passed
@atomiks
atomiks deleted the claude/lucid-lehmann-a04849 branch July 6, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: menu Changes related to the menu component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[menu] Multiple submenus are broken when moving mouse fast

2 participants