Repository navigation
[all components] Keep unpositioned popups at the viewport origin - #5299
flaviendelangle merged 1 commit into
Conversation
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]>
Bundle size
PerformanceTotal duration: 1,266.03 ms +71.58 ms(+6.0%) | Renders: 78 (+0) | Paint: 1,982.46 ms +97.78 ms(+5.2%)
13 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
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. |
|
Thanks for the feedback on X, that's super valuable for us to be able to improve the library 🙏 |
aarongarciah
left a comment
There was a problem hiding this comment.
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)
|
@yourdevujjawal the fix was tested in your repro repo as well. before Kapture.2026-07-21.at.20.40.41.mp4after after.mp4 |
|
It has some workarounds in the meantime:
|
…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 -->
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.Positioneris always kept mounted. While closed, the positioner can retain (or newly receive) coordinates computed while the popup measured 0×0 — withalign="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: 0hides that frame visually, but the element still participates in layout.The
!isPositionedfallback inuseAnchorPositioningwas meant to guard exactly this ("Default tofixedwhen not positioned … ensures the popup is inside the viewport initially"), but it was overridden:originalFloatingStylesre-appliesposition: absoluteplus 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
100vwbottom sheet), it ratchets: viewport ↑ → sheet ↑ →--anchor-width↑ → popup ↑ → more overflow. Measuredwindow.innerWidthexploding 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 becauseopenMethod === 'touch'disablesalignItemWithTrigger, taking theposition: absolutepath.Fix
While
!isPositioned, renderposition: fixed; top: 0; left: 0and ignore retained coordinates, as the fallback originally intended. After the fix, both repros keepinnerWidthstable at 412px and the popup lands on the anchor on every open.Testing
SelectPositioner.test.tsxasserting the kept-mounted positioner holds no stale coordinates while closed (fails without the fix:positionstaysabsolutewith the old transform).experiments/drawer/select-in-drawerfor manual verification in Chrome mobile emulation (open the drawer, open the select, select an item, reopen).Select/Popover/Menujsdom + 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: noneon<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