Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

Issue with fetching/caching data from Sanity.io in Next.js app deployed on Vercel.

4 replies
Last updated: Sep 1, 2023
Hey, I’m using next for building an application and I’ve followed the documentation of
"next-sanity": "5.4.6"
for fetching/caching the data from my studio.I want a very basic fetch method since it’s for a very simple website. In development it seems to works fine, but when deployed to
I have 0 fresh data.
Here is my
: (following the official doc )
import { createClient } from "next-sanity";

const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID;
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET;
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION;

export const client = createClient({
  useCdn: true,
  perspective: "published",

export async function sanityFetch<QueryResponse>({
}: {
  query: string;
}): Promise<QueryResponse> {
  return client.fetch<QueryResponse>(query, {
    next: { revalidate: 10 },
Here is how I fetch my metadata inside
export async function generateMetadata(): Promise<Metadata> {
  const layoutMetadata = await sanityFetch<TYPEMetadata>({
    query: META_QUERY,

  const metadata = layoutMetadata.meta;

  return {
    title: metadata.title,

is a valid
Aug 31, 2023, 5:47 PM
Did you add your env vars to Vercel?
Aug 31, 2023, 9:10 PM
user M
for the answer.Yes! everything fine this side
Aug 31, 2023, 9:32 PM
user M
It’s seems to works fine today, very very strange because I only did change and push UI since yesterday 😵‍💫.
Huge thanks for your time
user M
Sep 1, 2023, 1:48 PM
Glad it ended up working itself out!
Sep 1, 2023, 3:44 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?