Repository navigation
[popups] Mount the popup subtree synchronously on open in React 17 - #5309
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,038.64 ms -22.64 ms(-2.1%) | Renders: 78 (+0) | Paint: 1,598.74 ms -56.07 ms(-3.4%)
14 tests within noise — details 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. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a React 17-only first-open popup transition glitch by ensuring the portal subtree mounts synchronously on open, rather than being delayed waiting for the useId polyfill to assign an ID. It also adjusts how the portal node ID is surfaced/consumed so aria-owns can stay in sync on React 17.
Changes:
- Removes the React 17
useId-availability guard inuseFloatingPortalNodeso the portal container resolves immediately. - Exposes
portalNodeIdfromuseFloatingPortalNodeand uses it foraria-ownsinstead of readingportalNode.idfrom the DOM.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
In React 17, opening a popup for the first time skips the
.Popupenter transition (data-starting-styleis missing at mount) and lets the.Positionerslide in from the viewport origin. The subtree only misbehaves on the first open after mount; reopening works.The root cause is in
useFloatingPortalNode: it waits foruseIdbefore resolving the portal container. On React 17 theuseIdpolyfill assigns the id in a passive effect, and after a discrete input Chromium can paint before that flush runs, so the entire popup subtree mounts one task late — after the one-framestartingguard has already ended. (Reopening works because scheduling new React work force-flushes the pending passive effects synchronously.) The wait dates back to floating-ui/floating-ui#2778, when portal nodes were created imperatively and needed the id upfront to dedupe; the portal element is rendered by React now, so the guard is obsolete. Removing it lets the subtree mount within the opening task, and the portal div'sidattribute simply fills in once the polyfill resolves.aria-ownsnow reads the id from React state instead of the DOM node so it stays in sync on React 17.Verified with a React 17.0.2 Chromium repro (first and subsequent opens mount with
data-starting-styleand run the enter transition) and with the full popup-family suites on React 19. Note that the positioner's initial position can still race thestartingguard on React 17 in unlucky frames — consumers who transitiontransformon the Positioner should scope it away from the initial open; the deterministic fix for that requires store-subscription changes that aren't worth the bytes for React 17's share.Demo: https://stackblitz.com/edit/jpqdbqiv-tyrzftjr
Closes #5187