Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

terrymun
Copy link

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.

@terrymun
Copy link
Author

terrymun commented Dec 4, 2024

Hi @chaance, any idea if we could get this merged? That will fix a lot of the extraneous errors to those consuming React 19 with Radix :)

@V-iktor
Copy link

V-iktor commented Dec 6, 2024

Currently waiting on this to be able to upgrade my project 🚀

@terrymun
Copy link
Author

terrymun commented Dec 6, 2024

@V-iktor For the moment being I am simply using the modified <Slot> component (as per my PR) and configure it as an alias for my webpack's resolve.alias config:

webpack: (config) => {
  config.resolve = {
    ...config.resolve,
    alias: {
      ...config.resolve.alias,
      // TODO: Remove this shim once Radix fixes the issue with incorrect ref prop drilling
      //       https://github.com/radix-ui/primitives/issues/3224
      '@radix-ui/react-slot': path.resolve(__dirname, '/path/to/custom/slot.tsx'),
    },
  };

  return config;
},

If you're using another bundler/builder, you might need to consult their documentation on how to implement a similiar alias config. For example, Vite has a resolve.alias option: https://vite.dev/config/shared-options.html#resolve-alias

ggallon added a commit to ggallon/ai-chatbot that referenced this pull request Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants