Skip to content

[menu] Fix submenu safePolygon scope for keepMounted portals - #4723

Merged
atomiks merged 2 commits into
mui:masterfrom
twillhorn:codex/fix-menu-keep-mounted-safe-polygon
May 4, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
twillhorn:codex/fix-menu-keep-mounted-safe-polygon

Conversation

@twillhorn

@twillhorn twillhorn commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4722

This fixes submenu hover traversal when a submenu uses <Menu.Portal keepMounted>. In that case, the kept-mounted submenu can already be present in the floating tree before it opens, so safePolygon pointer-events scoping can resolve to the submenu itself. That scope does not shield sibling items in the parent menu, allowing sibling hover handling to close the submenu during diagonal pointer movement.

The change keeps the existing scope fallback order, but ignores cached or parent scope candidates when they are the current floating element. This lets the parent menu remain the pointer-events scope while the submenu positioner stays interactive.

Validation:

  • Confirmed the new regression test fails without the implementation change.
  • PLAYWRIGHT_BROWSERS_PATH=.playwright VITEST_ENV=chromium pnpm vitest run --project @base-ui/react packages/react/src/menu/root/MenuRoot.test.tsx -t "scopes submenu safePolygon"

@pkg-pr-new

pkg-pr-new Bot commented May 2, 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@4723
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4723
    

commit: b1bd644

@code-infra-dashboard

code-infra-dashboard Bot commented May 2, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+60B(+0.01%) 🔺+18B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,329.20 ms 🔺+108.88 ms(+8.9%) | Renders: 53 (+0) | Paint: 2,060.51 ms 🔺+173.62 ms(+9.2%)

Test Duration Renders
Dialog mount (300 instances) 101.28 ms 🔺+22.71 ms(+28.9%) 2 (+0)
Menu mount (300 instances) 140.95 ms 🔺+22.42 ms(+18.9%) 2 (+0)
Tooltip mount (300 contained roots) 74.69 ms 🔺+19.03 ms(+34.2%) 2 (+0)
Scroll Area mount (300 instances) 90.73 ms 🔺+15.32 ms(+20.3%) 3 (+0)
Checkbox mount (500 instances) 75.39 ms 🔺+14.32 ms(+23.4%) 1 (+0)

…and 7 more — details


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

@netlify

netlify Bot commented May 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit b1bd644
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69f7f5698b452a0008423d2c
😎 Deploy Preview https://deploy-preview-4723--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.

@twillhorn
twillhorn marked this pull request as ready for review May 2, 2026 04:41
@oliviertassinari oliviertassinari added the component: menu Changes related to the menu component. label May 2, 2026
@twillhorn

Copy link
Copy Markdown
Contributor Author

Tagging @atomiks because this touches the submenu hover pointer-events/safePolygon scope logic from #4231/#4199.

@atomiks atomiks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @twillhorn!

@atomiks
atomiks merged commit fd0179e into mui:master May 4, 2026
6 checks passed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[menu] Submenu safePolygon fails with keepMounted portal

3 participants