-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
getServerSideProps Fails to Serialize Date Object #13209
Comments
This check is necessary as we do not serialize props on the server for performance reasons. So, this check only runs in development and has you make things serializable with scalar types, meaning they'll match exact on the client. |
I'm having this issue when fetching data from Contentful on posts that have links to each other. Re:
Stringifying using import safeJsonStringify from 'safe-json-stringify';
...
export async function getServerSideProps({ params, preview = false }) {
const rawData = await getSlugPageProps(params.slug, 'product-page', preview);
const stringifiedData = safeJsonStringify(rawData);
const data = JSON.parse(stringifiedData);
return {
props: {
data
}
};
} |
I stumbled across the same problem and got it working with by using the |
@icflorescu I installed both packages and the .babelrc file and still getting the error.
|
I find it very strange that we have to do this when simply reading in a Date object. I guess there is a good reason? |
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. |
Bug report
Describe the bug
When passing a date over the getServerSideProps boundary, it fails to serialize the Date object. Dates are serializable, so they should be allowed through.
To Reproduce
Attempt to pass a date time through the API, like so
page/index.tsx
Expected behavior
Serializing occurs just fine
Screenshots
See Stack Trace
System information
Additional context
While crude, to not have to write complex logic to determine serializability, you could replace the offending method with
Stack Trade:
The text was updated successfully, but these errors were encountered: