SSG blog page doesn't update content on deployment triggered by webhook
Unanswered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
Hello all,
I don't fully know how to explain what is my issue but here goes my best.
I'm doing a refactor of a Blog ui app using ghost as the backend.
I have my blog pages using generateStaticParams() and dynamicParams = false as follows:
My fetch logic basically uses nextjs' fetch and i'm not setting any cache settigns:
I also have a webhook setup that triggers a deploy on vercel side every time there any change on any blog post. My logic here is that my pages being SSG i trigger a new build and therefore updating the post's content.
Problem is that is not happening. Every time that a new deployment/build happens the blog post content stays the same.
I've tried setting s cache:'no-store' setting in the fetch and that works, but then the build doesn't actually need to happen at all for the page to update, which almost sounds that the page is not SSG, am i wrong?
The build log says my pages are correctly SSG'd so i'm at a loss for words.
Appreciate all help
I don't fully know how to explain what is my issue but here goes my best.
I'm doing a refactor of a Blog ui app using ghost as the backend.
I have my blog pages using generateStaticParams() and dynamicParams = false as follows:
export const dynamicParams = false; // route segment config
// Return a list of params to populate the [slug] dynamic segment
export async function generateStaticParams() {
const posts = await getAllPosts();
return posts.map(({ slug }) => ({ slug }));
}
My fetch logic basically uses nextjs' fetch and i'm not setting any cache settigns:
const response = await fetch(apiUrl.toString(), {
headers,
method,
});
I also have a webhook setup that triggers a deploy on vercel side every time there any change on any blog post. My logic here is that my pages being SSG i trigger a new build and therefore updating the post's content.
Problem is that is not happening. Every time that a new deployment/build happens the blog post content stays the same.
I've tried setting s cache:'no-store' setting in the fetch and that works, but then the build doesn't actually need to happen at all for the page to update, which almost sounds that the page is not SSG, am i wrong?
The build log says my pages are correctly SSG'd so i'm at a loss for words.
Appreciate all help
33 Replies
you checked vercel build logs?
Asiatic LionOP
Yes everything looks ok, as far as i can see and i have the same information about the pages being SSG
is your API getting proper data, from where you're fetching posts?
Asiatic LionOP
Yes, i mean everything looks to work properly, including if i add a cache:'no-store' in the fetch object, the post gets correctly updated, but it feels like it's defeating the purpose of SSG, right?
hmm, I don't think so, if I'm not wrong, the fetch is cached, so while getting data, your data is old, so if you disable cache you're getting proper data without caching.
how does that affect SSG at all 

the ssg builds from the data you've received
doesn't matter old or new
Asiatic LionOP
i mean i always assumed SSG meant that the page gets generated at build time, but then shouldn't i get the newest data if i retrigger the build? my biggest issue with what's happening is that if i remove the cache, the page gets updated with out without retriggering a build, shouldn't the page just stay static since it was generated on build time?
hmm, never used ssg. so what I'm saying is purely based on what I heard, and docs I've read.
hmm
so if you're having
cache: no-store. you can access the posts even if they are not built at run time, that's what you are saying?Asiatic LionOP
no, if i have no-store i immediately see the updated content of posts without the need to regenerate the page (trigger a build/deploy) even if they are SSG pages
this is in prod right?
dumb question IK, but just to be sure
Asiatic LionOP
yes, which means for now i have a big no-cache on all my requests but i would like to see if i could "fix" that 😄
if I'm not wrong, even if the param is not generated at run-time. you still get the param data, and fetch it.
so, only built posts don't fetch data again, I suppose?
and the params/slug which has not been generated at buildtime will still show up, but will fetch data as dynamic instead of prebuild data in generated posts.
Note: I've no idea if what I'm saying is true, I just read docs, and saw someone using it. so don't mind me, if what I'm speaking is gibberish
American Crow
Data cache is persisted through deployments. Your prob want to do some on demand revalidation https://nextjs.org/docs/app/building-your-application/caching#data-cache
Asiatic LionOP
Another question then, i have a generateMetadata() function that fetches the post and generates a bunch of metatags and so on, and then on the component logic i also fetch the post information to display the different things (content, title, authors) in the metadata fetch i get the newest data but then on the component i get the, i assume, cached data, is this normal?
logs
the fetch code is exactly the same with exactly the same parameters being used:
const post = await getSinglePost(params.slug);
const post = await getSinglePost(params.slug);
@American Crow Data cache is persisted through deployments. Your prob want to do some on demand revalidation https://nextjs.org/docs/app/building-your-application/caching#data-cache
Asiatic LionOP
so my only option is to 100% opt out of cache? i don't want to have any delays on updating a post and then it showing up updated in the end user, hence i was hoping a webhook rebuilding the app would fix this issue since that was almost what i would get...
@Asiatic Lion so my only option is to 100% opt out of cache? i don't want to have any delays on updating a post and then it showing up updated in the end user, hence i was hoping a webhook rebuilding the app would fix this issue since that was almost what i would get...
American Crow
There are 4 types of caches in nextjs. Only one which can be persistent through deployments is the data cache. I don't see how purging it with your webhook is "100% opting out of caching"
Asiatic LionOP
sorry something might have been lost during translation. How exactly can i purge cache with my webhook?
American Crow
On demand revalidation section in the link I posted
Asiatic LionOP
but isn't all this code side? the webhook i have would simply just trigger a deploy on vercel side (it's a webhook ghost -> vercel)
American Crow
Ok we have a misunderstanding. I am talking about a webhook in your route handler which you call from (wherever) not constantly redeploying
Asiatic LionOP
ah ok i see what your saying... that might be an option, but i would like to have everything done by the one that redeploys, because i already have to have it to regenerate the sitemap whenever a new post is created.
@Asiatic Lion ah ok i see what your saying... that might be an option, but i would like to have everything done by the one that redeploys, because i already have to have it to regenerate the sitemap whenever a new post is created.
American Crow
I see. Maybe you can use some Vercle Env Variable for the revalidatoin tag e.g. VERCEL_DEPLOYMENT_ID . Never done that maybe worth a try