Skip to content

[popups] Restore viewport morphing after reopen - #5010

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:codex/popups-viewport-reopen
Jun 16, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
atomiks:codex/popups-viewport-reopen

Conversation

@atomiks

@atomiks atomiks commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

A kept-mounted popup viewport could skip its morphing snapshot after closing, reopening through one trigger, then switching back to the trigger it had handled before close. Reset the handled-trigger guard when the popup is closed so each open cycle can animate trigger switches normally.

Root cause

The last handled trigger was kept in a ref across close/reopen cycles, so a later switch to that same trigger was ignored.

Changes

  • Reset the handled trigger ref when the popup is closed or unmounted.
  • Add a kept-mounted viewport regression test for close, reopen, and trigger switch.

@atomiks atomiks added component: menu Changes related to the menu component. component: popover Changes related to the popover component. type: bug It doesn't behave as expected. labels Jun 11, 2026 — with ChatGPT Codex Connector
@pkg-pr-new

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

commit: d7e532e

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Bundle size

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

Details of bundle changes

Performance

Total duration: 1,182.32 ms 🔺+222.57 ms(+23.2%) | Renders: 50 (+0)

Test Duration Renders
Tabs mount (200 instances) 248.34 ms 🔺+62.40 ms(+33.6%) 4 (+0)
Checkbox mount (500 instances) 87.23 ms 🔺+28.95 ms(+49.7%) 1 (+0)
Scroll Area mount (300 instances) 90.96 ms 🔺+15.34 ms(+20.3%) 3 (+0)
Mixed surface mount (app-like density) 71.07 ms 🔺+13.59 ms(+23.7%) 5 (+0)
Menu open (500 items) 66.91 ms 🔺+12.70 ms(+23.4%) 12 (+0)

…and 6 more (+1 within noise) — details

Metric alarms

Test Metric Change
Tabs mount (200 instances) bench:paint 🔺 +104.63 ms
Checkbox mount (500 instances) bench:paint 🔺 +45.21 ms
Scroll Area mount (300 instances) bench:paint 🔺 +19.20 ms
Mixed surface mount (app-like density) bench:paint 🔺 +18.15 ms
Menu open (500 items) bench:paint 🔺 +24.98 ms
Menu open (500 items) bench:paint#menu-open 🔺 +24.98 ms
Dialog mount (300 instances) bench:paint 🔺 +18.22 ms
Slider mount (300 instances) bench:paint 🔺 +48.17 ms
Select mount (200 instances) bench:paint 🔺 +32.04 ms
Popover mount (300 instances) bench:paint 🔺 +18.56 ms
Tooltip mount (300 contained roots) bench:paint 🔺 +13.19 ms

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

@netlify

netlify Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit d7e532e
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a310667f77b7100080aca1e
😎 Deploy Preview https://deploy-preview-5010--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 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Code Review (GPT-5.5)

Approve ✅ No actionable issues found; the patch resets only the stale trigger guard across closed/unmounted cycles and the regression test reproduces the bug on base.

1. Bugs / Issues (None)

Root Cause & Patch Assessment

The fix targets the stale state directly: lastHandledTriggerRef can outlive a close/reopen cycle when the portal is kept mounted, so a later switch back to that trigger is incorrectly ignored. Resetting that ref when open or mounted goes false preserves the existing duplicate-handling guard while the popup is open.

Test Coverage Assessment

I verified the added regression test fails on freshly fetched upstream/master with only the test applied: after close/reopen/switch, [data-previous] stays null. On the PR branch, these targeted suites pass:

  • pnpm test:chromium PopoverViewport --no-watch
  • pnpm test:chromium MenuViewport --no-watch
  • pnpm test:jsdom PopoverViewport --no-watch
  • pnpm test:jsdom MenuViewport --no-watch

Performance / Operational Risk

Evidence Result Review take
code-infra bot +42B parsed, +16B gzip; total duration +41.25ms; renders +0 Not a blocker for this bug fix; the change adds one ref-reset layout effect and no render-count increase, but worth watching if a rerun repeats the duration/paint signal.

@atomiks
atomiks marked this pull request as ready for review June 11, 2026 05:07
@atomiks atomiks added scope: all components Widespread work has an impact on almost all components. and removed component: menu Changes related to the menu component. component: popover Changes related to the popover component. labels Jun 15, 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.

Pull request overview

This PR fixes a kept-mounted popup viewport edge case where morphing snapshots could be skipped after closing and reopening, by ensuring per-open-cycle trigger handling state is reset on close/unmount.

Changes:

  • Reset lastHandledTriggerRef whenever the popup is closed or becomes unmounted to avoid stale trigger-guard state across open cycles.
  • Add a browser-only regression test covering close → reopen → trigger switch for a keepMounted Popover viewport.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/react/src/utils/usePopupViewport.tsx Clears the “last handled trigger” ref when open is false or the popup is not mounted, restoring morphing behavior after reopen.
packages/react/src/popover/viewport/PopoverViewport.test.tsx Adds a regression test (non-JSDOM) to ensure morphing containers are created after a kept-mounted popup closes and reopens.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@atomiks
atomiks merged commit 802a5ba into mui:master Jun 16, 2026
6 checks passed
@atomiks
atomiks deleted the codex/popups-viewport-reopen branch June 16, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants