radix-ui / primitives

Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
https://radix-ui.com/primitives
MIT License
15.91k stars 831 forks source link

fix: do not pass ref into SlotClone component if children is a React.Fragment #3229

Open terrymun opened 6 days ago

terrymun commented 6 days ago

Description

This PR fixes the issue with consuming any Radix UI Primitive in React 19, which will throw the following error in the console (as reported in #3224):

385466239-382e4304-6fd9-468f-a32f-778a93bd4e0f

The error seems to arise from not checking the type of the children prop, which could potentially be a React Fragment that does not accept ref prop.

Therefore, the ref prop is only conditionally added to the props of the <SlotClone> element if children is not of type React.Fragment.