Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

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
Contributor

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
Contributor

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants