Skip to content

[popover][menu][tooltip][preview card] Don't start a viewport transition when the trigger remounts while closed - #5887

Merged
michaldudak merged 1 commit into
mui:masterfrom
michaldudak:claude/fix-popup-viewport-closed-remount
Oct 6, 2026
Merged

michaldudak merged 1 commit into
mui:masterfrom
michaldudak:claude/fix-popup-viewport-closed-remount

Conversation

@michaldudak

Copy link
Copy Markdown
Member

When a popup with a Viewport is closed but still mounted (for example via eventDetails.preventUnmountOnClose()), remounting its trigger starts a morph transition: the viewport renders a [data-previous] container with the old content, as if the user had switched triggers.

usePopupViewport tracks the previous trigger with usePreviousValue(open ? activeTrigger : null). After the popup closes, the tracked value stays null, so the "previous" value keeps pointing at the last open trigger. A remounted trigger is a new element, which differs from that stale value, so the trigger-change effect fires.

The fix only handles trigger changes while the popup is open. Opening from a closed state is unaffected: the previous value is null at that point, so no morph runs.

The hook is shared by Popover, Menu, Tooltip and PreviewCard viewports.

Why the existing test didn't catch it

PopoverViewport.test.tsx already has "does not restart a transition when the active trigger remounts while closed and retained", but its only assertion was that the viewport exists. It now also checks that the popup is closed, that the viewport isn't transitioning, and that there's no [data-previous] container.

Validation

  • The strengthened test fails without the source change (2 failures, strict and non-strict) and passes with it.
  • All *Viewport suites pass in jsdom and Chromium. ESLint and Prettier pass.

Found during an audit of the test suite for tests that can't fail.

…ion when the trigger remounts while closed

usePopupViewport tracks the previous trigger with
usePreviousValue(open ? activeTrigger : null). Once the popup closes, the
tracked value stays null and the previous value keeps pointing at the old
trigger element. When the trigger remounts while the popup is closed but kept
mounted, the new element differs from that stale previous trigger, so the
viewport captured the old content and rendered a [data-previous] container.

Only handle trigger changes while the popup is open.
@michaldudak michaldudak added component: menu Changes related to the menu component. type: bug It doesn't behave as expected. component: tooltip Changes related to the tooltip component. component: popover Changes related to the popover component. component: preview card Changes related to the preview card component. labels Oct 5, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 5, 2026

Copy link
Copy Markdown

commit: 9170cf4

@code-infra-dashboard

code-infra-dashboard Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+5B(0.00%) 🔺+5B(0.00%)

Details of bundle changes

Performance

Total duration: 432.58 ms +26.92 ms(+6.6%) | Renders: 76 (+0) | Paint: 784.71 ms +42.32 ms(+5.7%)

Test Duration Renders
Scroll Area mount (300 instances) 46.65 ms 🔺+12.28 ms(+35.7%) 3 (+0)

14 tests within noise — details

Metric alarms

Test Metric Change
Scroll Area mount (300 instances) bench:paint 🔺 +14.11 ms

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

@netlify

netlify Bot commented Oct 5, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

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

@michaldudak
michaldudak marked this pull request as ready for review October 5, 2026 13:41
@michaldudak
michaldudak merged commit 3e2c846 into mui:master Oct 6, 2026
28 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. component: popover Changes related to the popover component. component: preview card Changes related to the preview card component. component: tooltip Changes related to the tooltip component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant