Skip to content

[all components] Keep unpositioned popups at the viewport origin - #5299

Merged
flaviendelangle merged 1 commit into
mui:masterfrom
flaviendelangle:fix/kept-mounted-popup-stale-position
Jul 22, 2026
Merged

flaviendelangle merged 1 commit into
mui:masterfrom
flaviendelangle:fix/kept-mounted-popup-stale-position

Conversation

@flaviendelangle

Copy link
Copy Markdown
Member

Fixes the mobile Chrome bug reported for Select inside a sheet/drawer: the first open works, but reopening leaves the popup mispositioned (or the whole page zoomed out and "stuck"). Reproduces in Chrome mobile emulation and on Android; also reported against shadcn's Base UI-based components.

Root cause

Select.Positioner is always kept mounted. While closed, the positioner can retain (or newly receive) coordinates computed while the popup measured 0×0 — with align="center" the resulting x is the anchor's center. On reopen, the full-size popup is laid out at those stale coordinates for at least one frame before the fresh positioning pass lands. opacity: 0 hides that frame visually, but the element still participates in layout.

The !isPositioned fallback in useAnchorPositioning was meant to guard exactly this ("Default to fixed when not positioned … ensures the popup is inside the viewport initially"), but it was overridden:

{ position: resolvedPosition, ...originalFloatingStyles }

originalFloatingStyles re-applies position: absolute plus the stale transform, so the guard never took effect.

On desktop this is a harmless invisible frame. On mobile Chrome, the popup overflowing the layout viewport triggers scale-to-fit viewport expansion — and when the anchor's width follows the viewport (a full-width trigger inside a 100vw bottom sheet), it ratchets: viewport ↑ → sheet ↑ → --anchor-width ↑ → popup ↑ → more overflow. Measured window.innerWidth exploding 412 → 1648px (Chrome's minimum-scale 0.25 clamp) inside a Radix-based sheet, and 412 → 718px in a pure Base UI Drawer, with the popup rendered ~230px away from its trigger. Touch-only because openMethod === 'touch' disables alignItemWithTrigger, taking the position: absolute path.

Fix

While !isPositioned, render position: fixed; top: 0; left: 0 and ignore retained coordinates, as the fallback originally intended. After the fix, both repros keep innerWidth stable at 412px and the popup lands on the anchor on every open.

Testing

  • New Chromium regression test in SelectPositioner.test.tsx asserting the kept-mounted positioner holds no stale coordinates while closed (fails without the fix: position stays absolute with the old transform).
  • New experiment experiments/drawer/select-in-drawer for manual verification in Chrome mobile emulation (open the drawer, open the select, select an item, reopen).
  • Verified with Playwright touch emulation (Pixel 7) against the docs app: pure Base UI Drawer (2nd open) and a Radix modal bottom sheet (1st open, trigger force-mounted by the sheet's autofocus) both no longer expand the viewport.
  • Select/Popover/Menu jsdom + Chromium suites pass; no new TypeScript or lint errors.

App-level workaround for affected users until released: <meta name="viewport" ... minimum-scale=1> (Next.js: export const viewport = { minimumScale: 1 }).

Note: in Radix/vaul sheets there is a second, independent integration issue — Radix modal layers set pointer-events: none on <body>, which Base UI popups portaled to <body> inherit, making items untappable (shadcn-ui/ui#8814, shadcn-ui/ui#9130). Not addressed here.

🤖 Generated with Claude Code

A kept-mounted positioner rendered stale coordinates (including
positions computed while the popup measured 0x0) for a frame on reopen,
before the fresh positioning pass. The full-size popup laid out at
those coordinates can overflow the layout viewport, which makes mobile
Chrome zoom the page out; with anchors whose width follows the
viewport (e.g. a full-width select trigger inside a bottom sheet) this
feeds back on itself and the popup ends up detached from its anchor.

Render `position: fixed` at the viewport origin until a position is
computed, as the existing fallback already intended (it was overridden
by the spread of Floating UI's styles).

Co-Authored-By: Claude Fable 5 <[email protected]>
@code-infra-dashboard

code-infra-dashboard Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Bundle size

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

Details of bundle changes

Performance

Total duration: 1,266.03 ms +71.58 ms(+6.0%) | Renders: 78 (+0) | Paint: 1,982.46 ms +97.78 ms(+5.2%)

Test Duration Renders
Checkbox mount (500 instances) 78.86 ms 🔺+21.45 ms(+37.4%) 1 (+0)
Mixed surface mount (app-like density) 84.98 ms 🔺+14.90 ms(+21.3%) 5 (+0)

13 tests within noise — details

Metric alarms

Test Metric Change
Checkbox mount (500 instances) bench:paint 🔺 +26.64 ms

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

@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

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

@yourdevujjawal

Copy link
Copy Markdown

Thank you for addressing this issue. I had reported this on x (twitter) since I was facing these kind of issues with multiple components like sheet/drawer , select/popover etc.

@flaviendelangle

Copy link
Copy Markdown
Member Author

Thanks for the feedback on X, that's super valuable for us to be able to improve the library 🙏

@flaviendelangle flaviendelangle self-assigned this Jul 21, 2026
@flaviendelangle flaviendelangle added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. labels Jul 21, 2026

@aarongarciah aarongarciah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Working nicely.

before

_before.mp4

after

_after.mp4

PR review

The fix is correct and narrowly scoped: while !isPositioned, the positioner now renders position: fixed; top: 0; left: 0, which finally enforces the pre-existing fallback comment that the old spread order ({ position, ...originalFloatingStyles }) silently defeated. I traced the exit-animation, reopen-during-close, SSR/hydration, adaptiveOrigin, and alignItemWithTrigger paths and found no regressions: open is only passed to Floating UI for kept-mounted popups, and mounted stays true through exit transitions, so positioned coordinates are retained during close animations and only reset once the popup is hidden. The new Chromium test fails without the fix and passes with it, and all 8 *Positioner Chromium suites (226 tests) pass on the branch. Nothing is merge-blocking.

Tests (1)

1. ℹ️ Shared-hook fix is pinned only through Select's always-kept-mounted path

Location: packages/react/src/select/positioner/SelectPositioner.test.tsx:285

describe.skipIf(isJSDOM)('kept-mounted positioner', () => {
  it('does not retain stale coordinates while closed', async () => {

The fix lives in useAnchorPositioning and applies to every popup component, but the only regression test exercises Select, which hardcodes keepMounted: true internally. The prop-driven variant (<Popover.Positioner keepMounted> etc.) reaches the same code path, so this is optional — a small equivalent test on one prop-driven component would pin the keepMounted-prop wiring too.

Failure scenario: A future refactor of how keepMounted/mounted is threaded into useFloating for prop-driven positioners could regress the reopen behavior without failing this test.

Fix: Optionally duplicate the closed-state assertion in a keepMounted Popover or Menu positioner test.

Verdict

Approve — verified mechanism and regression test are sound, with no user-visible behavior risk found in any positioning path.


🤖 Review generated with Claude Code (Fable 5, max effort)

@aarongarciah

Copy link
Copy Markdown
Member

@yourdevujjawal the fix was tested in your repro repo as well.

before

Kapture.2026-07-21.at.20.40.41.mp4

after

after.mp4

@atomiks

atomiks commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

It has some workarounds in the meantime:

<Select.Positioner positionMethod="fixed"> (or <Select.Positioner align="start"> less generally)

@flaviendelangle
flaviendelangle merged commit bd2f34d into mui:master Jul 22, 2026
6 of 7 checks passed
@flaviendelangle
flaviendelangle deleted the fix/kept-mounted-popup-stale-position branch July 22, 2026 06:54
abhiaiyer91 pushed a commit to mastra-ai/mastra that referenced this pull request Aug 25, 2026
…still unmount (#22338)

TLDR: upgrades Base UI 1.5.0 → 1.7.0, which fixes the actual popup leak
behind the double-scrollbar bug: a popup whose exit animation gets
canceled by quick repeated interactions stayed mounted forever.

---

```
before   quick hovers across tooltips → exit canceled → popup mounted forever at opacity 0
after    canceled exit with no replacement animation still unmounts the popup
```

The double-scroll fix (#22329) contained the damage — a stale popup can
no longer grow the page — but the popup that got stuck was an upstream
bug, not tab-visibility timing as I first read it: base-ui's
`useAnimationsFinished` had no terminal state when an exit animation was
canceled without a replacement (mui/base-ui#5395, fixed by
mui/base-ui#5401). 1.7.0 also keeps unpositioned popups at the viewport
origin instead of stale absolute coordinates (mui/base-ui#5299) —
upstream converging on the same conclusion as #22329.

I reproduced the leak A/B in storybook (`Elements/Tooltip → AllSides`,
synthetic rapid cross-trigger hovers, uninterrupted tab visibility, 16
canceled-exit cycles):

```
1.5.0   2 tooltips left mounted after settle (data-open=false, opacity 0)
1.7.0   0
```

### Judgment call

Two minor versions in one jump. The 1.6/1.7 changelogs are bug fixes
only; the single rename (`OTPFieldPreview` → `OTPField`) touches nothing
we import. Full playground-ui (2564) and factory-ui (996) suites plus
both typechecks pass on 1.7.0.

### Not verified

The A/B repro is manual (storybook + synthetic pointer events) — no
automated regression test on our side. Upstream ships one with
mui/base-ui#5401, and the DS `fixed` positioning default independently
caps the blast radius if a future leak appears.

```
lockfile      +41  -36
source         +1   -1
changeset      +5    0
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## ELI5

This update uses a newer Base UI version. It prevents popups from
staying invisible and stuck on screen after quick tooltip interactions.

## Changes

- Upgraded `@base-ui/react` from `^1.5.0` to `^1.7.0`.
- Added a patch changeset for `@mastra/playground-ui`.
- Fixed interrupted popup exit animations that could leave popups
mounted at zero opacity.
- Prevented popups from reopening at stale absolute coordinates.

## Validation

- Playground UI and factory UI test suites passed.
- Typechecks passed.
- Manual Storybook testing confirmed that rapid tooltip interactions
leave no mounted popups.
- No automated regression test was added.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

4 participants