Reputation: 3861
The website of the company I work for is running Next.js on Vercel. The content is managed in Sanity.io and we use their cached API (served through a CDN) to fetch content. The exception is during the build process when we call the live API to ensure the most up-to-date content is retrieved. To handle this particular case, the CDN is enabled based on the absence of the CI
env var. And that works perfectly.
However, we have another scenario that doesn't work as expected: on-demand revalidation. It looks like the CI
variable is not exposed during the revalidation. Then, since the content change was just performed and the API response is still cached, the revalidation shows outdated content.
So, there is any way to know if on-demand revalidation is in progress in Next.js on Vercel? So I could call the live API to render a page during revalidation?
EDIT
Just in case, here is the config I'm using to set up the Sanity client:
export const config: ClientConfig = {
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || "production",
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || "",
apiVersion: "2022-01-05",
useCdn: !process.env.CI,
// Build steps (CI) don't use CDN to make sure it pulls the latest data from
// the (live) Sanity API.
};
I was trying to add a new condition to pair with the process.env.CI
variable.
Upvotes: 1
Views: 529