Replies: 1 comment
-
Relevant discussion: #11209 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Bug report
Describe the bug
I'm not sure it's a bug, in that there may be a reason for this behavior. But I can't wrap my head around it.
When returning a Javascript object from getStaticProps(), NextJS needs to serialize it to send it down to the page it's called from.
When I try to return a somewhat large and nested object that may have "undefined" values in it, Next complains that it needs "serializable" data and that
undefined
is not. It should be replaced bynull
values.However,
JSON.stringify()
does strips away undefined values. So why not allow undefined values? What serialization does NextJS do in the background?For large, nested objects, it might be complicated to remove/replace the undefined values except for resorting to JSON.parse(JSON.stringify(myObject)), which is not very nice although it works
To Reproduce
Nothing to do, just observe the error at:
https://codesandbox.io/embed/static-site-generation-ssg-in-nextjs-with-getstaticprops-4yu9h?fontsize=14&hidenavigation=1&module=%2Fpages%2Findex.tsx&theme=dark
Error message
Expected behavior
Let us return objects with
undefined
values as JSON.stringify() remove them anyway.System information
irrelevant/all
Beta Was this translation helpful? Give feedback.
All reactions