Skip to content

[popups] Mount the popup subtree synchronously on open in React 17 - #5309

Merged
atomiks merged 5 commits into
mui:masterfrom
atomiks:claude/react17-popup-positioner-002f32
Jul 23, 2026
Merged

atomiks merged 5 commits into
mui:masterfrom
atomiks:claude/react17-popup-positioner-002f32

Conversation

@atomiks

@atomiks atomiks commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

In React 17, opening a popup for the first time skips the .Popup enter transition (data-starting-style is missing at mount) and lets the .Positioner slide 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 for useId before resolving the portal container. On React 17 the useId polyfill 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-frame starting guard 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's id attribute simply fills in once the polyfill resolves. aria-owns now 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-style and run the enter transition) and with the full popup-family suites on React 19. Note that the positioner's initial position can still race the starting guard on React 17 in unlucky frames — consumers who transition transform on 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

@atomiks atomiks added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. component: portal Changes related to the portal component. labels Jul 23, 2026
@pkg-pr-new

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

commit: 1a116c6

@code-infra-dashboard

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

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-1B(0.00%) 🔺+10B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,038.64 ms -22.64 ms(-2.1%) | Renders: 78 (+0) | Paint: 1,598.74 ms -56.07 ms(-3.4%)

Test Duration Renders
Checkbox mount (500 instances) 76.58 ms 🔺+18.42 ms(+31.7%) 1 (+0)

14 tests within noise — details


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

@netlify

netlify Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 1a116c6
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a617a7327e517000853a816
😎 Deploy Preview https://deploy-preview-5309--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
atomiks marked this pull request as ready for review July 23, 2026 01:39
@atomiks
atomiks requested a review from Copilot July 23, 2026 01:42

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 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 in useFloatingPortalNode so the portal container resolves immediately.
  • Exposes portalNodeId from useFloatingPortalNode and uses it for aria-owns instead of reading portalNode.id from the DOM.

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

@atomiks atomiks removed the component: portal Changes related to the portal component. label Jul 23, 2026
@atomiks
atomiks merged commit b089a7c into mui:master Jul 23, 2026
7 checks passed
@atomiks
atomiks deleted the claude/react17-popup-positioner-002f32 branch July 23, 2026 02:31
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.

[popover] Positioner slides from viewport top-left on first open in React 17

2 participants