Sanity published changes not showing on your Next.js site
Published in Sanity Studio but your live site still shows old content? Fix Next.js caching with revalidateTag webhooks, useCdn: false, dataset mismatches, and drafts.
- sanity 6.24.0
- next-sanity 13.5.1
- Next.js 16.4.6
You hit Publish in Sanity Studio, refresh your live Next.js site, and the old text is still there. That happens for one of four reasons: Next.js cached the static route at build time with no revalidation webhook, your Sanity client has useCdn: true, the query filters out the document (wrong perspective or slug), or you published to a different dataset than production reads.
Check these four things in order
Step 1: Next.js cached the page (no webhook or revalidateTag)
In Next.js App Router, statically generated pages stay cached until you either set a time-based
revalidateor trigger on-demand revalidation from a Sanity webhook. Tag your Sanity fetches and expose a small webhook route:src/sanity/fetch.tsTypeScript export async function sanityFetch<T>(query: string, params = {}, tags: string[] = []) { return client.fetch<T>(query, params, { next: { revalidate: tags.length ? false : 60, tags }, });}app/api/revalidate/route.tsTypeScript import { revalidateTag } from "next/cache";import { parseBody } from "next-sanity/webhook";import { NextResponse, type NextRequest } from "next/server"; export async function POST(req: NextRequest) { const { isValidSignature, body } = await parseBody<{ _type: string }>( req, process.env.SANITY_REVALIDATE_SECRET, ); if (!isValidSignature) return NextResponse.json({ message: "Invalid signature" }, { status: 401 }); if (body?._type) revalidateTag(body._type, "max"); return NextResponse.json({ revalidated: body?._type ?? null });}Then create a GROQ-powered webhook in sanity.io/manage › API › Webhooks pointing to
https://yourdomain.com/api/revalidatewith the same secret.Step 2: useCdn: true returns a stale edge response
Sanity's API CDN (
apicdn.sanity.io) caches query results for a short window after publish. When you already cache pages in Next.js (with ISR orrevalidateTag), setuseCdn: falseon the server client so Next.js always fetches the freshly published document when it revalidates:src/sanity/client.tsTypeScript export const client = createClient({ projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!, dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!, apiVersion: "2026-11-01", useCdn: false,});Step 3: Studio and production point to different datasets
Check
NEXT_PUBLIC_SANITY_DATASETin your host's environment variables (Vercel, Cloudflare Workers, Netlify) against the dataset selected in Sanity Studio. Editing instagingwhile production readsproductionis a classic silent mismatch.Step 4: Document is still a draft or has a broken reference
Unpublished documents have an ID starting with
drafts.and are excluded by default underperspective: "published". If a parent page references a newly created author or category that is still a draft, the referenced fields resolve tonullon the live site until the referenced document is also published.
Questions
Does setting useCdn: false increase my Sanity API bill?
Only if every visitor hits the uncached API. When Next.js caches the route and only refetches on webhook or every 60 seconds, useCdn: false sends one API request per publish instead of one per visitor. You can estimate your monthly usage with our Sanity pricing calculator.
My browser console shows a CORS error when previewing drafts
That is a separate setting in Sanity's dashboard. Follow Fix Sanity CORS errors to add your preview origin with credentials enabled.
Where can I get ready-made Sanity schemas for Next.js and Astro?
Browse our free Sanity content models (posts, authors, FAQs, events, jobs) — copy the schema or install it with the shadcn CLI.
Related articles
- SanityFix Sanity CORS errors: add the right originAdd the exact origin (scheme, host, port) under API, CORS origins, with credentials where someone logs in. Why it can still fail after you added it.
- SanitySanity GROQ vs GraphQL: which query language to useCompare GROQ and GraphQL in Sanity: zero-deploy schema changes, inline joins, Sanity TypeGen with defineQuery, and when GraphQL still makes sense.
- SanityRender Sanity Portable Text in Next.js with Tailwind CSS v4Render Sanity Portable Text in Next.js Server Components with @portabletext/react and Tailwind CSS v4: headings, links, custom blocks, and typography.
Still stuck? We answer every message ourselves. Write to us