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

Encountered Static to Dynamic Error in Next.js production build #54

Closed
MonsterPi13 opened this issue Jan 24, 2024 · 4 comments
Closed

Comments

@MonsterPi13
Copy link
Contributor

MonsterPi13 commented Jan 24, 2024

Hi, I am encountering the "Static to Dynamic Error" in production after deploying my Next.js project. This error occurs when I publish a new post in Contentful and then visit that post's page on my site.

I believe the issue is related to generateStaticParams function usage in the /writing/[slug] route. Pages are statically generated at build time, but then fail when visiting a page that was not part of the initial build, so it will change into dynamic.

My current workaround is adding export const dynamic = 'force-dynamic' in the page file, but this disables static generation entirely.

I'm looking for advice on the best way to handle this since I'm new to Next.js. Should I redeploy the site every time I publish a new post in order to rebuild all static pages? Or is there a way to incrementally build only new pages? Appreciate any suggestions you may have!

@suyalcinkaya
Copy link
Owner

Hi, I'm using Contentful and it supports webhooks. So whenever I publish a blog post, it automatically triggers the deployment process, resulting in the rebuilding of all static pages.

@MonsterPi13
Copy link
Contributor Author

MonsterPi13 commented Jan 25, 2024

Hi, I'm using Contentful and it supports webhooks. So whenever I publish a blog post, it automatically triggers the deployment process, resulting in the rebuilding of all static pages.

Thank you for your reply. I'm using Contentful for the first time today.

May I ask for some advice regarding webhooks?

Are you adding two webhooks - one to revalidate the /writing route and another to update /writing/[slug] when publishing, unpublishing, or deleting any entries?

I appreciate any guidance you can provide as I get started with leveraging Contentful webhooks appropriately.

i see related revalidate code as blow:

  const path = requestHeaders.get('path') ?? '/'
  revalidatePath(path)

@suyalcinkaya
Copy link
Owner

I'm using just one webhook from Contentful and putting it in Vercel to rebuild the whole website to revalidate the cache. And the revalidatePath is only for manually revalidating a specific path.

I'm closing this as it's not an issue. I've recently enabled the Discussions, so if you have any questions, feedback, or ideas, please feel free to reach out to me there. 🤞

@MonsterPi13
Copy link
Contributor Author

MonsterPi13 commented Jan 26, 2024

I'm using just one webhook from Contentful and putting it in Vercel to rebuild the whole website to revalidate the cache. And the revalidatePath is only for manually revalidating a specific path.

I'm closing this as it's not an issue. I've recently enabled the Discussions, so if you have any questions, feedback, or ideas, please feel free to reach out to me there. 🤞

Thanks for your reply.

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

No branches or pull requests

2 participants