Strange error in nextjs for a single nested route

I keep getting the following error when trying to access a specific sub-document in nextjs:

Error: Error serializing .slices returned from getStaticProps in "/shop/[uid]".
Reason: undefined cannot be serialized as JSON. Please use null or omit this value all together.

The strange part is this works for all my other nested routes like blog posts and events it seems this one specific type is cursed or something. What specifically is this error message referring to?

Ok so I got to the bottom of this and I'm pretty sure this is a bug. So this happens when you are using a document that does not have a slice zone with slice machine. For instance my events, posts, and product pages are not slice zone enabled but I was happily using the lifecycle hooks just like the slice zone documentation. My events and posts were working fine but this is because there is a "body" parameter that defaults to body which was one of the keys in my document data.

For products this was not the case and so of course this failure was driving me nuts until I saw the "body" key in the documentation. I instead just set this to the description key and all was working well.

export const getStaticProps = useGetStaticProps({
  client: Client(),
  type: 'product',
  body: 'description',
  uid: ({ params }) => params.uid

This is rather unexpected and I'm pretty sure this is a hack. Albeit I think it's rather nice to be able to use these hooks for pages without slice zone but this is extremely unexpected behavior and I would have realized this folly sooner had I not coincidentally made a "body" field in my events and posts documents.

Anyway hoping to help someone else that hits this but it would also be great to know if this is intentional or going to be patched over.

Hey Mike,

I'm glad you figured this out but I'm sorry you ran in to this issue to being with. I'm going to pass this on to the Devs, hopefully they can implement something more elegant for users who run in to the same issue.


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.