Error serializing props returned from `getServerSideProps` in "/[slug]" when accessing a page.
39 replies
Last updated: Jan 25, 2022
Why isn’t my [slug].js page displaying when going to the page?I keep getting this error
This is what my getServerSideProps looks like
I’ve used this ^ structure on a different slug page and it works
error - Error: Error serializing props returned from `getServerSideProps` in "/[slug]". Reason: Props must be returned as a plain object from getServerSideProps: `{ props: { ... } }` (received: `[object Null]`).
export const getServerSideProps = async function (context) { const { slug = '' } = context.query; const data = await client.fetch(`*[_type == "hikes" && slug.current == $slug][0] `, { slug }); return { props: data }; };
Jan 25, 2022, 10:01 PM
error - Error: Error serializing props returned from `getServerSideProps` in "/[slug]". Reason: Props must be returned as a plain object from getServerSideProps: `{ props: { ... } }` (received: `[object Null]`).
Jan 25, 2022, 10:05 PM
const data = await client.fetch(`*[_type == "hikes" && slug.current == $slug][0] `, { slug }); console.log(data)
Jan 25, 2022, 10:06 PM
import client from '../lib/sanity' export default function Hikes({ data }) { console.log(data) return( <main> </main> ) } export const getServerSideProps = async function (context) { const { slug = '' } = context.query; const data = await client.fetch(`*[_type == "hikes" && slug.current == $slug][0] `, { slug }); console.log(data) return { props: { data } }; };
Jan 25, 2022, 10:09 PM
Got ya. It’s a GROQ playground, so can be useful.
sanity install @sanity/vision
Jan 25, 2022, 10:11 PM
Thanks. So I can confirm that
should return data. I find a bit weird that you’re getting a 404 though. Even if there no data, the page template should’ve returned those empty
client.fetch(`*[_type == "hikes" && slug.current == $slug][0]`, { slug: "2022-01-24" })
<main>. This is a file in the
pagesfolder, right?
Jan 25, 2022, 10:17 PM
Correct, I have a hike folder in the pages folder. Inside the /hike is an index and [slug]
Jan 25, 2022, 10:18 PM
So, I get this working here, maybe you could compare this to your setup?
https://codesandbox.io/s/cranky-wood-jymbk?file=/pages/hike/%5Bslug%5D.js / https://jymbk.sse.codesandbox.io/hike/2022-01-24
https://codesandbox.io/s/cranky-wood-jymbk?file=/pages/hike/%5Bslug%5D.js / https://jymbk.sse.codesandbox.io/hike/2022-01-24
Jan 25, 2022, 10:24 PM
Jan 25, 2022, 10:32 PM
and thanks! I watched something that said it could improve your relationship with your dog (once you realize what you do with them everyday) and at the very least you have a story of them at the end of their life
Jan 25, 2022, 10:37 PM
Totally understandable – it’s way easier for me to spot stuff like that coming in fresh
Jan 25, 2022, 10:37 PM
Looking forward to learning more about the site once you have launced it and told i-made-this 😄
Jan 25, 2022, 10:37 PM
I do have it already deplyed https://dog-journal.vercel.app/
I’m committing to the
52 Hike challenge which is why I’m now building the hike part of the site
I’m committing to the
52 Hike challenge which is why I’m now building the hike part of the site
Jan 25, 2022, 10:39 PM
V
user G
I was just reading this for nerd reasons initially but that is a gorgeous dog.Jan 25, 2022, 10:49 PM
😍 This is a fantastic project - on all accounts. (
user G
, have you seen this?)Jan 25, 2022, 11:01 PM
😍 This is a fantastic project - on all accounts. (
user G
, have you seen this?)Jan 25, 2022, 11:01 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.