Skip to content

[all components] Fix prop and ref merging for lazy render elements - #5562

Merged
atomiks merged 4 commits into
mui:masterfrom
atomiks:lazy-render-element-unwrap
Aug 26, 2026
Merged

atomiks merged 4 commits into
mui:masterfrom
atomiks:lazy-render-element-unwrap

Conversation

@atomiks

@atomiks atomiks commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #5431
Fixes #5561

useRenderElement read the render element's props (mergeProps(props, render.props)) and its ref (getReactElementRef) before the #3856 lazy unwrap. A lazy render element, which is what the Flight client hands a Client Component when a Server Component element gets deferred into its own payload row, has no .props or .ref. Its props therefore lost the documented precedence (the component's own props silently won) and its ref was never attached. Since Flight defers based on payload size, the server and client passes could disagree, which surfaced as hydration mismatches in Next.js App Router apps.

Changes

  • Unwrap the lazy element once at the top of useRenderElement, before the ref extraction and the prop merge, instead of just before cloneElement. The unwrap is skipped when enabled: false, since unwrapping a pending lazy element suspends and the disabled path never suspended before.
  • Added regression tests using the Flight lazy element shape, gated to React 19+ because Children.toArray only unwraps lazy elements there (which also means the [all components] Support lazy element in render prop #3856 workaround was already React 19-only).

@atomiks atomiks added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. labels Aug 25, 2026
@pkg-pr-new

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

commit: 0aec317

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+91B(+0.02%) 🔺+17B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,578.61 ms +195.38 ms(+14.1%) | Renders: 76 (+0) | Paint: 2,565.41 ms +373.47 ms(+17.0%)

Test Duration Renders
Select mount (200 instances) 189.07 ms 🔺+46.24 ms(+32.4%) 3 (+0)
Menu mount (300 instances) 131.81 ms 🔺+39.71 ms(+43.1%) 1 (+0)
Menu open (500 items) 102.59 ms 🔺+21.53 ms(+26.6%) 11 (+0)
Mixed surface mount (app-like density) 104.41 ms 🔺+21.05 ms(+25.2%) 5 (+0)
Tooltip mount (300 contained roots) 76.28 ms 🔺+17.78 ms(+30.4%) 1 (+0)

…and 5 more (+5 within noise) — details

Metric alarms

Test Metric Change
Select mount (200 instances) bench:paint 🔺 +65.72 ms
Menu mount (300 instances) bench:paint 🔺 +58.92 ms
Menu open (500 items) bench:paint 🔺 +43.87 ms
Menu open (500 items) bench:paint#menu-open 🔺 +43.87 ms
Mixed surface mount (app-like density) bench:paint 🔺 +32.40 ms

…and 9 more metric alarms — details


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

@netlify

netlify Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

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

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

1 participant