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

React 19 breaking with this.props.children #31832

Open
2xOu7 opened this issue Dec 18, 2024 · 7 comments
Open

React 19 breaking with this.props.children #31832

2xOu7 opened this issue Dec 18, 2024 · 7 comments

Comments

@2xOu7
Copy link

2xOu7 commented Dec 18, 2024

Hello,

Our code is now breaking when we upgrade to React 19. It seems related to this.props.children, and it works fine in React 18. I have attached the error and a screenshot of where the code is breaking.

[Error: Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner}). If you meant to render a collection of children, use an array instead.]
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner}). If you meant to render a collection of children, use an array instead.

Screenshot 2024-12-18 at 12 09 59 AM
@2xOu7 2xOu7 added the React 19 label Dec 18, 2024
@2xOu7 2xOu7 changed the title [React 19] React 19 breaking with this.props.children Dec 18, 2024
@eps1lon
Copy link
Collaborator

eps1lon commented Dec 18, 2024

Whatever is in this.props.children is likely JSX from another version of React. We often got these reports when people used 3rd party dependencies that inlined the JSX runtime in their build process when it should be an external.

I recommend removing as much code as possible from this Component tree until it no longer reproduces. That should help identifying the offending Component.

@micky0001
Copy link

check this might be useful for you
render(): Element {
const { microCopiesToRender, isPreviewMode } = this.state;

// Validate `this.props.children`
const validChildren = React.Children.map(this.props.children, (child) => {
    if (React.isValidElement(child)) {
        return child;
    }
    console.error("Invalid child found:", child);
    return null; // or handle invalid children gracefully
});

if (!microCopiesToRender) {
    return <>{validChildren}</>;
}

return (
    <MicrocopyContext.Provider
        value={{ copies: microCopiesToRender ?? [], isPreview: isPreviewMode }}
    >
        {validChildren}
    </MicrocopyContext.Provider>
);

}

@2xOu7
Copy link
Author

2xOu7 commented Dec 18, 2024

@eps1lon
Nothing's logging when I put the code above. It breaks on build without me even running the code.

The only child of the class is a paragraph element as of now, so no third party dependencies. The code screenshot above is part of an npm library that I am writing and trying to import into another project.

Everything works works completely fine when I build my npm library with React 18 and I make the other project also use React 18 (or if both use React 19), but any mismatch between React versions causes stuff to break.

@2xOu7
Copy link
Author

2xOu7 commented Dec 18, 2024

Update: Even with no children, it breaks!

@piokasar
Copy link

I am also seeing this issue unfortunately.

@davecarlson
Copy link

Do an npm ls react and npm ls react-dom.

If you see packages using 18, this is why it's happening, as there's a mistmatch between 19 and 18. I'd recommend looking into the effected packages and maybe helping them raise PR's to update their deps/peerDeps

@2xOu7
Copy link
Author

2xOu7 commented Dec 26, 2024

It sounds like this is a backwards compatibility issue - is there no intention to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants