-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[material-ui][Box] Box throws an error when there is a RSC (React Server Component) as a child #39928
Comments
Getting the prop type warning for Box component. https://codesandbox.io/p/sandbox/fragrant-forest-gn5rr6?file=%2Fsrc%2Fapp%2Fpage.tsx%3A1%2C1 Warning: Failed prop type: Invalid prop `children` supplied to `ForwardRef(Box)`, expected a ReactNode. |
This is the PropType that's causing the error: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Box/Box.js#L26 I guess we could change it to I believe this doesn't work in "plain" react, only in Next.js: async function FooBar() {
return <Box>foobar</Box>
}
export default function Page() {
return (
<Box>
<FooBar />
</Box>
)
} |
@mj12albert I was wondering if prop-types package supports the pattern of using RSC as a child. |
Can confirm it happens, and not only with <Box>
<div>
<MyServerComponent />
</div>
</Box> the error goes away. Not ideal because of the useless extra div, but works fine so far. |
I found another solution based on @FernandVEYRIER one, without extra div element.
'use client';
import React from 'react';
export const ClientToServer: React.FC<{
children: React.ReactNode;
}> = ({ children }) => {
return <>{children}</>;
};
<Box>
<ClientToServer>
<MyServerComponent />
</ClientToServer>
</Box> |
How about changing it to |
Please see facebook/prop-types#407 |
We could:
|
Steps to reproduce 馃暪
Link to live example: https://codesandbox.io/p/devbox/fragrant-forest-gn5rr6?file=%2Fsrc%2Fapp%2Fpage.tsx%3A1%2C1
Current behavior 馃槸
Throws the following error:
Expected behavior 馃
Not error =D
Context 馃敠
Absolutely love MUI, but this is preventing us from using it in server components
Your environment 馃寧
System:
OS: macOS 13.6
Binaries:
Node: 18.17.0 - ~/.nodenv/versions/18.17.0/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.6.7 - ~/.nodenv/versions/18.17.0/bin/npm
Browsers:
Chrome: 119.0.6045.159
Edge: Not Found
Safari: 16.6
The text was updated successfully, but these errors were encountered: