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

Can't pass server component to PropTypes.node #407

Open
Janpot opened this issue Feb 4, 2024 · 6 comments
Open

Can't pass server component to PropTypes.node #407

Janpot opened this issue Feb 4, 2024 · 6 comments

Comments

@Janpot
Copy link

Janpot commented Feb 4, 2024

Nesting a server component inside a client component that has PropTypes.node defined for its children results in a warning:

Warning: Failed prop type: Invalid prop `children` supplied to `WithPropTypes`, expected a ReactNode.

Reproduction: https://stackblitz.com/edit/stackblitz-starters-tn6djg?file=app%2Fpage.tsx

@ljharb
Copy link
Collaborator

ljharb commented Feb 4, 2024

Since when can a component be an async function?

@Janpot
Copy link
Author

Janpot commented Feb 4, 2024

Since when can a component be an async function?

I guess since Next.js started supporting React server components. Assuming you're not looking for an exact date 😄

@Janpot
Copy link
Author

Janpot commented Feb 4, 2024

Actually, just noticed the same happens when rendering lazy components as children

const MyLazyComponent = React.lazy(() => import('./Component'));

@oliviertassinari
Copy link

oliviertassinari commented Feb 4, 2024

I think we should also check that propTypes.element works.

For the root of the issue, we might want to check that isValidElement works:

if (propValue === null || isValidElement(propValue)) {

https://react.dev/reference/react/isValidElement

@ljharb
Copy link
Collaborator

ljharb commented Feb 4, 2024

I’m pretty sure that hasn’t been released in react proper, and next.js just jumped the gun.

I’ll try to look into it, though, since it’s likely that they’re all the same issue.

@Janpot

This comment was marked as outdated.

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

3 participants