Next.js Discord

Discord Forum

Calling Revalidation Route within Serverless function doesn't revalidate page

Unanswered
Somali posted this in #help-forum
Open in Discord
Avatar
SomaliOP
Hello,

I'm using on-demand revalidation for a path within my application. I have 2 serverless functions, one that updates the database contents for the page, and another one to revalidate the page (using response.revalidate). When a user updates the page contents, the first serverless function is called to update the database content. That same serverless function also uses fetch to call a post request to the second serverless function, which revalidates the page.

My issue is that calling fetch within the first serverless function to revalidate the page doesn't work as expected. The second serverless function executes, and returns a valid response, however, the page is not updated with the correct content (is still serves stale content). What's interesting is that calling same serverless function to revalidate the page using Curl, postman, or using fetch within the frontend application works, and revalidates the page correctly. I'm not sure why calling it within the first serverless function doesn't work as expected?

6 Replies

Avatar
Does this persist on build/prod?
On prod, the Cache Control header is overriden so it should always stay cached
Avatar
SomaliOP
its work locally, but when deployed to vercel, it doesn't work.
The response from the second serverless function (that revalidates the route), is not cached. I validated this by adding a timestamp field in the response
Avatar
Have you tried using revalidatePath instead
Avatar
SomaliOP
I'm using pages directory, not sure if it works with that