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

Bug: Children.map raises error when passed async server component within client component #28806

Closed
mfosterw opened this issue Apr 10, 2024 · 4 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@mfosterw
Copy link

React version: 14.1.4

Steps To Reproduce

  1. In a Next.js app or another framework that uses React server components, create an async server component called Child
  2. Create a client component called Client which accepts the children prop and returns Children.map(children, (child) => child)
  3. Create a server component called Parent, and return Child inside Client

Link to code example: https://codesandbox.io/p/devbox/broken-water-4kktmz

The current behavior

Raises Error: Objects are not valid as a React child (found: object with keys {$$typeof, _payload, _init}). If you meant to render a collection of children, use an array instead.

The expected behavior

Returns an unresolved Promise representing the child.

@mfosterw mfosterw added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 10, 2024
@TheJarX
Copy link

TheJarX commented Apr 15, 2024

This is just a comment; just trying to note that the documentation includes some alternatives to Children. Did you try with any of those alternatives?

https://react.dev/reference/react/Children#alternatives

@mfosterw
Copy link
Author

This issue actually arose for me through a Mantine component calling Children.toArray. Here is the code, and if you can think of an alternative way to do what they're doing I can try to suggest it. It seems to me like there's no good alternative for the use case.

@LuBustos
Copy link

@mfosterw
I am using next v14.2.0 and it works well, try updating your next version and check if it works.

@mfosterw
Copy link
Author

Updating Nextjs fixed it, thanks @LuBustos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants