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

[DropdownMenu] Using asChild on <DropdownMenu.Item> throws React.Children.only error #583

Open
decanTyme opened this issue Sep 10, 2024 · 0 comments

Comments

@decanTyme
Copy link

decanTyme commented Sep 10, 2024

I have a component that does a simple thing:

<DropdownMenu.Item asChild>
  <Flex justify="center" align="center" gap="4" py="6" mb="-1">
    <Avatar
      src={profile.picture}
      alt={profile.username}
      fallback={profile.username[0]}
      size="4"
      radius="full"
    />
    <Text size="3" weight="bold">
      {profile.username}
    </Text>
  </Flex>
</DropdownMenu.Item>

The problem is it throws:

image

After hours of digging, I tracked it down to this specific line of code

{shortcut && <div className="rt-BaseMenuShortcut rt-DropdownMenuShortcut">{shortcut}</div>}

And the <DropdownMenuPrimitive.Item> children becomes essentially a children array [{…}, undefined] that this line will check and throw
https://github.com/radix-ui/primitives/blob/660060a765634e9cc7bf4513f41e8dabc9824d74/packages/react/slot/src/Slot.tsx#L72

Sure enough commenting it out seems to fix the problem.

I'm not familiar with RadixUI internals so I would appreciate any help with this if I'm even doing this right. The only other thing to note is that it somehow worked with Create React App, which I'm trying to migrate off of to Vite which now has this problem.

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

No branches or pull requests

1 participant