-
Notifications
You must be signed in to change notification settings - Fork 26.3k
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
Application breaks when returning circular references from getServerSideProps #21364
Comments
Usage of |
@timneutkens How do you handle cases where you need circular references? For instance, when you load some database entities which are linked to each other, creating circular references. Is it a valid approach to serialize them using Flatted, and return them from getServerSideProps and then parse it back in _app (using Flatted). I don't see any issue with that, as long as it's just one props that is being serialized this way, and not the whole props object. It'd still be JSON.stringify by Next.js as expected by the framework. |
@timneutkens Why is it intended and what's the importance for React Server Components? |
Hey @timneutkens We'd love your feedback here. :) |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
10.0.3
What version of Node.js are you using?
14.4.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
Whenever a circular referenced object is returned from
getServerSideProps
the application breaks which is clearly not ideal.I'd recommend the usage of Flatted instead of
JSON.stringify | parse
to serialized/deserialize objects.Expected Behavior
Even when returning circular referenced objects the application should not break.
To Reproduce
Just try to return a circular referenced object like on
getServerSideProps
:This is what Next Right Now is doing to avoid issues, but I think it should be the default behaviour of Next.js. (UnlyEd/next-right-now#270)
Thanks!
The text was updated successfully, but these errors were encountered: