Next.js Discord

Discord Forum

Huge bug? GetStaticProps not running for certain routes

Unanswered
DennisK posted this in #help-forum
Open in Discord
As you can see in the video, when i click on the card it will go to that specific page. Only in development it does not fire anything inside getStaticProps anymore until I manually hard refresh the page or insert the url myself

What could this be and is this a known thing?

12 Replies

no I haven't seen this before. I noticed the console in vscode is not fully visible in the bottom, it might be the video recording but are you sure it is showing the most updated logs? instead of the top of the terminal
Yup, I am sure 😦 It appears do happen on dynamic pages but only on routes which has an index and [slug]. Home, regular pages and 80% of the other routes are working though..

In production we dont have this behaviour. It is generating all routes without any errors
export const getStaticProps: GetStaticProps<
  PageProps,
  Query,
  PreviewData
> = async (context) => {
  const preview = context.draftMode || false;
  const previewToken = preview ? process.env.SANITY_READ_TOKEN : ``;

  const client = getClient(previewToken);

  const [data, settings] = await Promise.all([
    client.fetch(BLOG_QUERY, context.params),
    client.fetch(SETTINGS_QUERY),
  ]);

  const notFound = !data;
  return {
    props: {
      data,
      settings,
      preview,
      previewToken: previewToken || null,
    },
    notFound,
  };
};
But it is not even getting at getStaticProps or paths
Hmm. console.logged getStaticpaths and this one is running with succes. Its returning me the array of slugs. After that, it will get stuck in development

export const getStaticPaths: GetStaticPaths = async () => {
  const paths = await client.fetch(SLUG_BLOG);

  const formattedPaths = paths.map((slug: { slug: string }) => ({
    params: { slug: slug.slug },
  }));

  return { paths: formattedPaths, fallback: false };
// Returns [ { params: { slug: 'development-blog-pagina-2' } }, { params: { slug: 'development-blog-pagina' } } ]
};
my first suggestion is to fix the return type of getStaticProps to not include the notFound prop together with props
so something similiar to
return data
  ? {
      props: {
        data,
        settings,
        // ...
      },
    }
  : { notFound: true }
otherwise next will see the props property and continue rendering the page (even if it doesn't exist)
if the issue still persists even on the latest version then I would look into creating a small reproduction and opening an issue in the Next.js repo since it indeed looks like a bug
Its a big private repo, just tried to replicate it using the issue template but I can't replicate it. Is there a way maybe to come in contact with someone and give them access to the repo?
you could try sending a message to Lee in twitter or creating a post in https://github.com/vercel/next.js/discussions saying you are open to giving access to the repo for investigation. but they are usually kinda busy so it might take some time to get a response
I do see something. In the vercel logs i do see slugs I dont even have available.

So if I go inside my route /products and click on slug-a. I will see that it randomly return 500 errors (in the logs) on routes like /products/vacancies. While vacancies is another folder/route