-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Passing children
as props to a react component breaks in production.
#5493
Comments
children
as props to a react component does not work.children
as props to a react component breaks in production.
mark |
Hello Dude, |
@wulinsheng123 I've read them. It doesn't mention this use case. If you weren't supposed to pass children as props, i'd expect an error. |
|
I'm perfectly aware that this works. I'm saying |
Yup, you get this because of the bug in astro (SSR HTML is inconsistent with client rendered HTML), react then switches to client rendering and rerenders the component. In production it doesn’t, so the component is blank (gets serialized to children=null). |
What happens in regular client-side (non-Astro) React when you pass it a prop named |
import React from "https://esm.sh/react@18";
import ReactDOM from "https://esm.sh/react-dom@18";
const Test = (props) => {
return (
<div>{props.children}</div>
)
}
const App = () => {
return(
<>
<div className="box">
<h1>Passing string children as prop</h1>
<Test children="prop" />
</div>
<div className="box">
<h1>Passing string children both as prop and children</h1>
<Test children="prop">children</Test>
</div>
</>
);
}
ReactDOM.render(<App />,
document.getElementById("root")) |
What version of
astro
are you using?1.6.11
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
yarn
What operating system are you using?
linux
Describe the Bug
If you're passing
children
as a prop to a react component from a.astro
file, instead of doing it via markup, eg:The component will receive
{children: null}
when building. It works fine inastro dev
, but breaks inastro build
when the island is loaded. Since this is perfectly viable React code, i'd regard this as a bug.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-l4gigd
Participation
The text was updated successfully, but these errors were encountered: