-
Notifications
You must be signed in to change notification settings - Fork 27.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
Circular Structure Error When passing complex objects with circular reference to another server component or function in Next 15 #72189
Comments
This looks like a React issue to be honest, but I am still collecting info.
Discussion answer: #72225 (comment) |
Thanks so much for looking into it. Do you think it is safe to assume that this bug will be worked out, and that it is acceptable coding practice to pass complex objects with circular reference as component parameters in nextjs 15? |
That I don't know. I think we can try to make a smaller reproduction demo, without any additional libraries etc, and try to ping Seb Markbåge, to get their opinion. Assuming this problem is caused because, we try to serialize data, to display in the DevTools, then there should be some kind of way out. From MDN:
|
Here is a minimal Stackblitz fork: https://stackblitz.com/edit/nextjs-wwb9nh?file=app%2Fpage.tsx,package.json function Child(props: unknown) {
console.log(props);
return <div></div>;
}
export default function Home() {
const props: Record<string, unknown> = {};
props.props = props;
return <Child {...props} />;
}
In Next 14, we'd log: <ref *1> { props: [Circular *1] } But in Next 15, I guess with a bumped React family version, we error out. Maybe upon a serialising error, we should try to fallback on old behaviour? Again, this looks like something to fix upstream on React itself. @sebmarkbage sorry to ping ya, could you confirm this? Looks like an odd minor issue ~ |
The error also appears if you pass a complex object through a component (as opposed to just a function). Component parameters get stringified also, which triggers the error. |
Link to the code that reproduces this issue
https://github.com/webplantmedia/html-react-parser/tree/master/examples/nextjs
To Reproduce
I can't seem to pass complex objects to other server components or functions without getting a circular structure error. Specifically, I'm using html-react-parser and manipulating certain elements to render custom jsx. It worked fine and without error in nextjs 14.
layout.tsx
page.tsx
Error:
package.json
I just pushed a commit with the code. Thanks so much for looking into it! I have based a very big next js project in using this react parser. I'm hoping there is an easy fix to this without having to refactor lots of code.
https://github.com/webplantmedia/html-react-parser/tree/master/examples/nextjs
Current vs. Expected behavior
The bug is not being able to pass a complex object to different server functions or server components. It was not an issue in Next 14.
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
I tested with next 15.0.2
The text was updated successfully, but these errors were encountered: