Skip to content

[menu] Fix event listener cleanup in MenuTrigger component - #5764

Merged
michaldudak merged 5 commits into
mui:masterfrom
sai6855:menu-trigger-effect-clean-up
Sep 21, 2026
Merged

michaldudak merged 5 commits into
mui:masterfrom
sai6855:menu-trigger-effect-clean-up

Conversation

@sai6855

@sai6855 sai6855 commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

This is the 5th PR in react-doctor series. Previous PR's #5760 #5761

This PR adds missing clean up function in useEffect

@pkg-pr-new

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

commit: 24b5a76

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Bundle size

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

Details of bundle changes

Performance

Total duration: 1,027.50 ms -168.62 ms(-14.1%) | Renders: 76 (+0) | Paint: 1,723.51 ms -258.38 ms(-13.0%)

Test Duration Renders
Mixed surface mount (app-like density) 71.23 ms ▼-21.93 ms(-23.5%) 5 (+0)
Menu mount (300 instances) 71.01 ms ▼-19.63 ms(-21.7%) 1 (+0)
Select open (500 options) 59.32 ms ▼-19.42 ms(-24.7%) 14 (+0)
Menu open (500 items) 67.96 ms ▼-18.10 ms(-21.0%) 11 (+0)

11 tests within noise — details


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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Cleanup can be skipped after the open reason changes, leaving a stale listener attached.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds cleanup for the document-level mouseup listener used by hover-opened menu triggers.

Changes:

  • Removes the listener when the effect cleans up.
File Description
packages/​react/​src/​menu/​trigger/​MenuTrigger.tsx Adds document listener cleanup logic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@netlify

netlify Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 24b5a76
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6aae7a794624540008647035
😎 Deploy Preview https://deploy-preview-5764--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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The cleanup breaks drag-outside cancellation for normally pressed menu triggers.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

@sai6855
sai6855 requested a balanced review from Copilot September 19, 2026 11:09
@sai6855 sai6855 added docs Improvements or additions to the documentation. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels Sep 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Regression coverage is needed to verify listener removal when the menu closes or unmounts before mouseup.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The new test does not exercise the listener-cleanup regression.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The cleanup is correctly scoped to the owning document and the regression test covers the reported lifecycle case.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@sai6855
sai6855 marked this pull request as ready for review September 19, 2026 12:27
@sai6855
sai6855 requested a review from jjenzz as a code owner September 19, 2026 12:27
@michaldudak michaldudak added component: menu Changes related to the menu component. type: bug It doesn't behave as expected. and removed docs Improvements or additions to the documentation. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels Sep 21, 2026
@michaldudak
michaldudak merged commit 218c9e8 into mui:master Sep 21, 2026
28 checks passed
flaviendelangle added a commit to flaviendelangle/base-ui that referenced this pull request Oct 28, 2026
…ize-neutral

- Drop `usePressReleaseListener`. Menu and Context Menu keep their own
  listeners, Select and Combobox keep `{ once: true }`, and Menu's mui#5764
  test is back.
- `isPressReleasedInside(event, trigger, positioner, list?)` takes
  positional args and uses the trigger for the bounds check. Menu walks
  the menu tree itself, so `findRootOwnerId` stays in `menu/utils`.
- Context Menu's unmount cleanup test now waits out the long-press window
  before unmounting, so it fails without the cleanup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants