Skip to content

[popups] Fix positioner not repositioning to a different trigger when reopened with keepMounted - #4407

Merged
atomiks merged 3 commits into
mui:masterfrom
mdm317:fix-popup-keepmounted-position
Mar 23, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
mdm317:fix-popup-keepmounted-position

Conversation

@mdm317

@mdm317 mdm317 commented Mar 21, 2026 •

Copy link
Copy Markdown
Contributor

fixes #4222

This issue occurs in all components that have a popup and use keepMounted.

  1. Go to https://base-ui.com/experiments/preview-card/triggers
  2. Enable the keepMounted option.
  3. In Uncontrolled, multiple triggers within Root, do: hover => unhover => hover another trigger.
  4. The popup position changes unexpectedly.

The same issue also appears in these components: tooltip, popover, and menu.
new link : https://deploy-preview-4407--base-ui.netlify.app/experiments/preview-card/triggers

@pkg-pr-new

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

commit: 00939a8

@mui-bot

mui-bot commented Mar 21, 2026 •

Copy link
Copy Markdown

Bundle size report

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

Details of bundle changes


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

@netlify

netlify Bot commented Mar 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 5aa87a1
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69c0fae2f60914000935430c
😎 Deploy Preview https://deploy-preview-4407--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@mdm317
mdm317 marked this pull request as ready for review March 21, 2026 17:06
@atomiks

atomiks commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Codex Review (GPT-5.4)

This is a focused bug-fix PR in shared popup positioning. The positionReference reset matches the stale-reference failure mode for keepMounted reopen flows, and the added Chromium regression reproduces the preview-card case directly.

1. Bugs / Issues (None)

2. Root Cause & Patch Assessment

Area Assessment Notes
Root-cause fit Strong Resetting positionReference on the closed keepMounted path addresses the store state that was still pointing at the previous trigger when the popup reopened.
Patch scope Narrow The change is a single store reset in the shared positioning hook, which keeps the blast radius small.
Shared-hook impact Appropriate This bug lives below the component layer, so fixing it in useAnchorPositioning is the right level.

3. Pattern Consistency Assessment

Area Status Notes
Floating root sync Consistent The reset now matches the other fields already nulled on close, so the store no longer carries stale reference state across reopen cycles.
Reopen behavior Improved The hook can now resume from a clean reference state instead of inheriting the last trigger’s positioning input.

4. Simplification Opportunities

No simplification issue stands out here. The patch is already minimal and directly tied to the bug.

5. Edge Cases Worth Noting

Area Status Notes
Preview-card hover path Covered The new test exercises the reported close-then-reopen path with keepMounted.
Nearby shared positioning behavior Low risk pnpm test:chromium PopoverPositioner --no-watch also passed, which is a useful sanity check on another keepMounted consumer.

6. Test Coverage Assessment

Strengths: The new Chromium regression is well targeted. It verifies that the positioner aligns to trigger 1, remains mounted while hidden, then realigns to trigger 2 after reopen.

Gaps: The PR description says the same bug reproduces in tooltip, popover, and menu as well, but this branch only adds the explicit reopen-and-reposition regression for preview-card. Because the fix is in the shared hook, I do not see evidence of a remaining runtime defect from the code itself, but adding at least one click-driven keepMounted multi-trigger regression in popover or menu would better protect that broader claim over time.

Validation run: pnpm test:chromium PreviewCardRoot.detached-triggers --no-watch and pnpm test:chromium PopoverPositioner --no-watch both passed.

Merge Confidence Score

Dimension Score Notes
Root cause coverage 4/5 The fix lines up with the stale-reference failure mode.
Regression coverage 4/5 The reported preview-card path is explicitly covered; adjacent popup families are still relying on shared-hook confidence rather than their own dedicated regression.
Validation evidence 4/5 Targeted Chromium validation passed on the new regression and one nearby shared-hook consumer.

Overall merge confidence is 4/5. I would be comfortable merging this as-is; adding one more cross-family regression would just improve long-term protection for the broader PR claim.

@atomiks atomiks added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. labels Mar 23, 2026
@atomiks atomiks changed the title [preview-card] Fix positioner not repositioning to a different trigger when reopened with keepMounted [popups] Fix positioner not repositioning to a different trigger when reopened with keepMounted Mar 23, 2026
@atomiks
atomiks merged commit d6c13ee into mui:master Mar 23, 2026
4 of 6 checks passed
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.

[preview card] keepMounted breaks detached trigger pattern

3 participants