Most "my Sanity edit is not showing" bugs in a Next.js site come from two caches, not one. Sanity's own Next.js documentation says the Sanity API CDN "introduces a short delay before new content is available", while the Next.js data cache is controlled separately by revalidate times and tags, so a page "can be stale because of either layer or both" (Sanity docs, read 17 November 2026). Get that model right and most of the integration falls into place.
This guide covers what the pairing is for, the three ways to connect the two, the one we would choose, a step list, what breaks and what it costs at scale. Every limit comes from Sanity's, Next.js's or Vercel's own documentation and pricing pages, read on 17 November 2026.
What the pairing is for
Sanity is a headless CMS: content lives in its hosted Content Lake, editors work in Sanity Studio, and the site queries it with GROQ. Next.js renders that content on the server and decides how long to cache it. Teams pick the pair when the site is more than pages, for example a marketing site sharing components with a product, a content model with many references, or editors who want click-to-edit previews of a custom front end.
The integration has one job: a published edit should reach the live page within a predictable time, and editors should see drafts in context without those drafts leaking to the public site.
If you are still choosing the front end, see "Webflow or Next.js for a Marketing Site? The Decision in Four Questions". If the CRM side matters as much as the CMS side, "Next.js + HubSpot: The Integration Guide, With the Gotchas (2026)" covers forms and attribution. This page assumes Next.js and Sanity are both decided.
The three ways to connect them
There are three working patterns for getting published content into pages, plus a separate choice about where the Studio lives.
| Method | How it works | Freshness | Best for | Main risk |
|---|---|---|---|---|
| Cached fetch plus webhook | Server components query Sanity; queries are tagged; a Sanity webhook calls a Route Handler that runs revalidateTag or revalidatePath | Seconds after the webhook fires, if both cache layers are cleared | Mostly static marketing sites, teams not yet on Next.js 16 | Missed webhooks and wrong tag names leave pages stale indefinitely |
| Live Content API via defineLive | next-sanity's defineLive returns sanityFetch and a SanityLive component that listens for changes and refreshes affected queries | Near real time; eventually consistent by default | Sites that want Visual Editing and live previews | Strict version requirements and a new caching model to learn |
| Client-side fetch | The browser queries the API CDN directly with @sanity/client | Depends on the CDN cache | Search boxes, filters and widgets on top of a server-rendered page | Content missing from the initial HTML, and private datasets need a token you cannot ship |
Sources: Sanity docs, Caching and revalidation in Next.js, Add live content to your application, Configuring the Sanity client for Next.js (read 17 November 2026)
Cached fetch plus webhook. Sanity describes this as manual caching. Its sanityFetch helper defaults to a 60 second revalidate, and once you pass tags the cache "lives indefinitely until a webhook busts it". Tags and time-based revalidation are mutually exclusive for each query, so pick one per query, not per site.
Live Content API. Sanity's docs call defineLive "the recommended approach for most applications". In next-sanity v13, SanityLive uses a stale-while-revalidate profile by default, so updates are eventually consistent. For instant updates, including clearing CDN caches, the docs pair it with a Sync Tag Invalidate Function.
Client-side fetch. Useful as a layer, not a foundation. The client's own docs set useCdn to true by default and say to turn it off "when you need the freshest data or are performing mutations".
Where the Studio lives. Sanity Studio can be mounted inside the Next.js app at a catch-all route such as app/studio/[[...tool]]. Sanity calls this "convenient for small to medium projects" and recommends a standalone Studio or monorepo for larger teams.
The route we would use, and why
For a B2B marketing site on Next.js 16, we would use defineLive for content pages and embed the Studio in its own route group. We build applications in Next.js, so this is the stack we would choose for our own work, and we state that bias plainly. We have not yet shipped this exact setup for a client, so treat the choice as our reading of the documentation rather than a case study.
defineLive handles the published and draft perspectives, stega encoding for click-to-edit and cache refreshes from one helper, which removes most of the hand-written webhook code. With the published perspective it uses the CDN; draft perspectives bypass it. The Studio in a route group keeps one repository, one deploy and one CORS origin to manage.
We would fall back to cached fetch plus webhooks in two cases: a site that cannot move to Next.js 16 and React 19.2.3 yet, or a mostly static site where editors do not need live previews and a delay of a few seconds is fine.
Step list
- Check versions first. For defineLive in next-sanity v13: Next.js 16, App Router, React 19.2.3 or later, @sanity/client 7.28.0 or later, and cacheComponents false in next.config unless you follow Sanity's Cache Components guide.
- Install. Run npx sanity@latest init inside the Next.js project, or install next-sanity and @sanity/image-url by hand.
- Set environment variables. Project ID and dataset can be public. Create a Viewer token in sanity.io/manage under API, Tokens, and store it as a server-only variable such as SANITY_API_READ_TOKEN, never with the NEXT_PUBLIC prefix.
- Configure the client. Pin apiVersion to a date. Sanity's Next.js example defaults to 2026-03-01. Leave useCdn on for published reads.
- Call defineLive. Export sanityFetch and SanityLive, render SanityLive in the site layout, and fetch only through sanityFetch in server components.
- Mount the Studio. Add the catch-all route, render NextStudio, and make sure basePath in sanity.config matches the route exactly. Export the metadata from next-sanity/studio, which sets robots to noindex.
- Add CORS origins. Add every front-end origin, with credentials allowed, in the Sanity project settings or with npx sanity cors add. Missing origins make live updates fail with 403 errors.
- Wire draft mode and Presentation. Create /api/draft-mode/enable with defineEnableDraftMode, point the Presentation Tool's previewMode.enable at it, set stega.studioUrl, and render VisualEditing only when draft mode is on.
- Add a webhook only where needed. If you stay on manual caching, create a GROQ-powered webhook filtered to your document types, with a secret of at least 32 characters, pointing at a Route Handler that uses parseBody.
What breaks: tokens, webhooks, caching and preview
| Area | What goes wrong | The documented rule |
|---|---|---|
| Tokens | Draft previews leak or fail | browserToken is sent to the browser in draft mode, so it must be a Viewer token |
| Tokens | Pages render empty, no error | A private dataset queried without a token returns empty results, not an error |
| CORS | Live updates fail with 403 | Each front-end origin must be listed with credentials allowed |
| Webhooks | Edit never reaches the site | Two retries 30 seconds apart; 4xx except 429 is treated as undeliverable |
| Webhooks | Duplicate deliveries | Delivery is at least once; each request carries an idempotency-key header |
| Webhooks | Draft edits ignored | drafts. and versions. documents are skipped by default |
| Caching | Fresh webhook, stale page | The API CDN and the Next.js data cache are separate layers |
| Caching | Deprecation warning or no effect | revalidateTag now takes a second argument; tags over 256 characters are never assigned |
| Preview | Odd characters in titles or broken equality checks | Stega adds invisible characters to strings; use stega false in generateMetadata and stegaClean before comparisons |
| Limits | 429s during large builds | 500 uncached requests per second per client IP; 500 concurrent queries per dataset |
Sources: Sanity docs on live content, webhooks, Next.js webhooks, visual editing and technical limits; Next.js revalidateTag reference (read 17 November 2026)
Tokens. The tidy rule: published content needs no token on a public dataset, drafts always do. The trap is a private dataset. Without a token the query succeeds and returns nothing, so the page renders empty and nothing appears in your error logs.
Webhooks. Sanity retries a failed delivery twice, 30 seconds apart, and notes this limit may change. A deploy that takes the revalidation route down for two minutes can therefore lose an edit for good. Return 2xx quickly, treat a 401 with isValidSignature of null as a missing sanity-webhook-signature header, and use the idempotency-key header to ignore repeats. In a Route Handler, parseBody reads the raw body for you; in the Pages Router you must turn bodyParser off and check the signature yourself.
Caching. In Next.js 16, revalidateTag with the recommended "max" profile marks data stale and serves the old version while it refetches. A webhook usually wants revalidateTag(tag, { expire: 0 }) instead, which the Next.js docs suggest when the call comes from outside a Server Action. If content is still old after that, the CDN is the suspect, which is why parseBody waits 3 seconds by default.
Preview. Stega encoding is what makes click-to-edit work, and it is also what corrupts a meta title if you forget stega false in generateMetadata, or a slug if you forget it in generateStaticParams.
Cost at scale
The front-end hosting is rarely the large bill. Seats, documents and extra datasets are.
| Item | Entry point | What scales it |
|---|---|---|
| Sanity Free | $0; 20 seats; 10,000 documents; 2 public datasets; 250,000 API and 1 million API CDN requests a month | No overage: you hit a wall instead of a bill |
| Sanity Growth | $15 per seat a month, up to 50 seats; 25,000 documents; 100 GB bandwidth | API requests $1 per 25,000; CDN requests $1 per 250,000; bandwidth $0.30 per GB |
| Sanity Growth add-ons | Increased quota $299 a month: 50,000 documents, 5 million CDN and 1 million API requests | Extra dataset $999 each |
| Live and webhooks | Free and Growth list 1,000 live connections per dataset; 2 or 4 GROQ-powered webhooks | Enterprise, custom pricing |
| Vercel Pro hosting | $20 a month plus $20 per developer seat, with a $20 usage credit | Functions from $0.60 per million; ISR writes from $4 per million; 1 TB transfer, then $0.15 per GB |
Sources: Sanity pricing page and technical limits; Vercel pricing page (read 17 November 2026)
A worked example. Five editors on Growth cost $75 a month. If a cached site still sent 3 million CDN requests in a month, the 2 million above the allowance would cost $8. The real cliffs are elsewhere: a programmatic content model that passes 25,000 documents moves you to the $299 add-on, and a separate staging dataset beyond the two included costs $999.
One figure we could not pin down: the pricing page lists 1,000 live connections per dataset on Free and Growth, the technical limits page lists 1,000 or 5,000 concurrent listeners, and Sanity's live content guide implies visitors' browsers connect to receive published updates. Ask Sanity how SanityLive visitor connections count before you rely on it for a high-traffic site.
What this means for a team wiring Next.js to Sanity
Decide on freshness and preview first. If editors want click-to-edit and the codebase can be on Next.js 16, use defineLive, keep tokens on the server and keep the Studio in its own route group. If the site is mostly static, tag your queries, revalidate from a signed webhook with an immediate expiry, and accept that a missed webhook is a stale page until the next edit. Either way, plan for documents and datasets, not servers. Our web apps service page explains how we would scope an integration like this.


