NextJS dynamic pages not working on first load

I have a NextJS site with multiple dynamic pages and I’m using Next’s getServerSideProps to get the query name that will be used to fetch data.
I’m getting errors in my site’s console and it looks like it’s trying to fetch data before getting the query name.
The problem is that everything is working in local but in prod it’s not.

Here’s the log for when I try to access a dynamic page:

Nov 10, 01:41:20 PM: ec28e815 INFO   [GET] /_next/data/N8JHeVUvhft2u6V1iPItK/pokemon/bulbasaur.json?name=bulbasaur (SSR)
Nov 10, 01:41:20 PM: ec28e815 Duration: 6.21 ms	Memory Usage: 273 MB
Nov 10, 01:41:23 PM: 0494421b INFO   [GET] /pokemon/react_devtools_backend_compact.js.map (SSR)
Nov 10, 01:41:23 PM: 0494421b Duration: 69.79 ms	Memory Usage: 273 MB
Nov 10, 01:42:03 PM: e4b6fafd INFO   [GET] /pokemon/bulbasaur (SSR)
Nov 10, 01:42:03 PM: e4b6fafd Duration: 20.93 ms	Memory Usage: 273 MB
Nov 10, 01:42:04 PM: 6cff3684 INFO   [GET] /api/auth/session (SSR)
Nov 10, 01:42:04 PM: 6cff3684 Duration: 5.10 ms	Memory Usage: 273 MB

The first log is when I try to access the page and it doesn’t work and the third log is when I refresh the page and it works.

Here’s my site: pokeref.app

I’m using Next 13.4.19

Hi @Tixarer , thanks for the post.
If possible can you share a code snippet of the getServerSideProps

Thanks.

Here’s the getServerSideProps for the dynamic page in the log:

export function getServerSideProps(context: GetServerSidePropsContext) {
  const { name } = context.query;
  return {
    props: {
      name,
    },
  };
}

Visiting a URL like this directly: pokeref.app/pokemon/bulbasaur, seems to work fine. So as far as SSR is concerned, it’s working. What I noticed is not working is going from your home page to one of the characters. Your frontend is polling undefined for some reason, and that part is happening in your client-side JavaScript as far as I can check.

1 Like

So it could be the link that’s broken ? It’s weird that it’s working in local but not in prod.

I don’t know what exactly is broken in your setup, I just stated what seems like an issue to me. Your links are pointing to undefined for some reason - now I don’t know where that undefined is coming from exactly to be able to pin-point the issue.