Skip to content
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

Only when preview mode is on, the newly added slug page can be seen. #212

Open
AruhaMaeda opened this issue Feb 13, 2023 · 5 comments
Open
Labels

Comments

@AruhaMaeda
Copy link

AruhaMaeda commented Feb 13, 2023

I want to ask whether this is a bug or something wrong setting.

Only when preview mode is on, the newly added slug page can be seen.
If I exit from preview mode, get 404.

  • I deployed from Vercel template, and I added CORS setting to my sanity project. (I don't change any code. )

  • video is below

Next.js.Blog.with.Sanity.io.Desk.-.13.February.2023.1.mp4
@choutkamartin
Copy link
Contributor

choutkamartin commented Feb 13, 2023

Are you sure you set up the webhook that revalidates and triggers a page rebuild correctly? Webhooks also have an attempt log, that can show you if the revalidate function has been called correctly, and if not, what may be wrong.

@choutkamartin
Copy link
Contributor

choutkamartin commented Feb 13, 2023

@AruhaMaeda Also, this may be a bad fallback setting.

Take a look at this:

// pages/posts//[slug].tsx
export const getStaticPaths = async () => {
  const slugs = await getAllPostsSlugs()

  return {
    paths: slugs?.map(({ slug }) => `/posts/${slug}`) || [],
    fallback: false,
  }
}

Do you see that fallback false? Well, that is probably the problem, because:


Sanity: Hey, Next.js, I changed some content, I sent you a request to revalidate some pages.

Next.js API: Let me take a look at which pages you want to revalidate. Oh, you want to revalidate articles too? Ok, I revalidated almost all articles except the new one, you have created. But that article wasn't generated at the build time so I can't revalidate it! It's fallback property is set to false, meaning if I can't find the page, I have to return 404 and don't generate it.


Yeah, so it's probably because of this. Setting it to "blocking" will probably help. You can find more information in Next.js documentation.

return {
    paths: slugs?.map(({ slug }) => `/posts/${slug}`) || [],
    fallback: "blocking",
  }

https://nextjs.org/docs/api-reference/data-fetching/get-static-paths#fallback-false
https://stackoverflow.com/questions/67787456/what-is-the-difference-between-fallback-false-vs-true-vs-blocking-of-getstaticpa

@AruhaMaeda
Copy link
Author

AruhaMaeda commented Feb 14, 2023

Thank you for your response!

As you said, I didn't set up revalidates so I did it but still did not reflect the changes correctly.

Finally, as you suggested, I changed fallback false to blocking, and it works! Thank you very much.

return {
    paths: slugs?.map(({ slug }) => `/posts/${slug}`) || [],
    fallback: "blocking",
  }

@choutkamartin
Copy link
Contributor

@AruhaMaeda Glad you got it working! I opened a PR: #213

@maksimay
Copy link

maksimay commented Apr 5, 2024

@AruhaMaeda Also, this may be a bad fallback setting.

Take a look at this:

// pages/posts//[slug].tsx
export const getStaticPaths = async () => {
  const slugs = await getAllPostsSlugs()

  return {
    paths: slugs?.map(({ slug }) => `/posts/${slug}`) || [],
    fallback: false,
  }
}

Do you see that fallback false? Well, that is probably the problem, because:

Sanity: Hey, Next.js, I changed some content, I sent you a request to revalidate some pages.

Next.js API: Let me take a look at which pages you want to revalidate. Oh, you want to revalidate articles too? Ok, I revalidated almost all articles except the new one, you have created. But that article wasn't generated at the build time so I can't revalidate it! It's fallback property is set to false, meaning if I can't find the page, I have to return 404 and don't generate it.

Yeah, so it's probably because of this. Setting it to "blocking" will probably help. You can find more information in Next.js documentation.

return {
    paths: slugs?.map(({ slug }) => `/posts/${slug}`) || [],
    fallback: "blocking",
  }

https://nextjs.org/docs/api-reference/data-fetching/get-static-paths#fallback-false https://stackoverflow.com/questions/67787456/what-is-the-difference-between-fallback-false-vs-true-vs-blocking-of-getstaticpa

thanks so much for this, had the same problem this fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants