Guides

Next.js + Sanity: The Integration Guide, With the Gotchas (2026)

How to connect Next.js to Sanity in 2026: the three ways to fetch content, the setup we would pick, the step list, and what breaks in tokens, webhooks, caching and preview.

Summarize with AI
Octo Agency cover: Next.js + Sanity, with a purple hexagon pattern

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.

Three ways to fetch Sanity content in Next.js
MethodHow it worksFreshnessBest forMain risk
Cached fetch plus webhookServer components query Sanity; queries are tagged; a Sanity webhook calls a Route Handler that runs revalidateTag or revalidatePathSeconds after the webhook fires, if both cache layers are clearedMostly static marketing sites, teams not yet on Next.js 16Missed webhooks and wrong tag names leave pages stale indefinitely
Live Content API via defineLivenext-sanity's defineLive returns sanityFetch and a SanityLive component that listens for changes and refreshes affected queriesNear real time; eventually consistent by defaultSites that want Visual Editing and live previewsStrict version requirements and a new caching model to learn
Client-side fetchThe browser queries the API CDN directly with @sanity/clientDepends on the CDN cacheSearch boxes, filters and widgets on top of a server-rendered pageContent 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

  1. 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.
  2. Install. Run npx sanity@latest init inside the Next.js project, or install next-sanity and @sanity/image-url by hand.
  3. 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.
  4. Configure the client. Pin apiVersion to a date. Sanity's Next.js example defaults to 2026-03-01. Leave useCdn on for published reads.
  5. Call defineLive. Export sanityFetch and SanityLive, render SanityLive in the site layout, and fetch only through sanityFetch in server components.
  6. 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.
  7. 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.
  8. 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.
  9. 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

Common failure points and the documented rule behind each
AreaWhat goes wrongThe documented rule
TokensDraft previews leak or failbrowserToken is sent to the browser in draft mode, so it must be a Viewer token
TokensPages render empty, no errorA private dataset queried without a token returns empty results, not an error
CORSLive updates fail with 403Each front-end origin must be listed with credentials allowed
WebhooksEdit never reaches the siteTwo retries 30 seconds apart; 4xx except 429 is treated as undeliverable
WebhooksDuplicate deliveriesDelivery is at least once; each request carries an idempotency-key header
WebhooksDraft edits ignoreddrafts. and versions. documents are skipped by default
CachingFresh webhook, stale pageThe API CDN and the Next.js data cache are separate layers
CachingDeprecation warning or no effectrevalidateTag now takes a second argument; tags over 256 characters are never assigned
PreviewOdd characters in titles or broken equality checksStega adds invisible characters to strings; use stega false in generateMetadata and stegaClean before comparisons
Limits429s during large builds500 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.

What grows with the site, and what it costs
ItemEntry pointWhat scales it
Sanity Free$0; 20 seats; 10,000 documents; 2 public datasets; 250,000 API and 1 million API CDN requests a monthNo 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 bandwidthAPI requests $1 per 25,000; CDN requests $1 per 250,000; bandwidth $0.30 per GB
Sanity Growth add-onsIncreased quota $299 a month: 50,000 documents, 5 million CDN and 1 million API requestsExtra dataset $999 each
Live and webhooksFree and Growth list 1,000 live connections per dataset; 2 or 4 GROQ-powered webhooksEnterprise, custom pricing
Vercel Pro hosting$20 a month plus $20 per developer seat, with a $20 usage creditFunctions 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.

Frequently asked questions

Is next-sanity required to use Sanity with Next.js?

No, but it saves most of the work. You can query Sanity with @sanity/client and handle caching yourself. next-sanity adds defineLive and SanityLive for live content, NextStudio for embedding the Studio in a route, parseBody for verifying webhooks and an Image component built on next/image. Sanity's docs call defineLive the recommended approach for most applications. Note that the next-sanity/image API is labelled alpha and may change in a minor release, according to its README.

Why does my Sanity edit not show on my Next.js site?

Usually because one of two caches is still serving the old version. The Sanity API CDN adds a short delay, and the Next.js data cache keeps tagged queries until something revalidates them. Check that the webhook fired, that the tag name in the query matches the one revalidated, and that the handler waited for the Content Lake. Sanity's docs suggest logging fetches with logging.fetches.fullUrl to see cache hits and misses.

Should I embed Sanity Studio in my Next.js app?

For a small or medium project, embedding is simpler: one repository, one deploy, and the Studio at a route such as /studio. Sanity recommends a standalone Studio or a monorepo for larger teams, partly to stop the content model becoming shaped around one website. If you embed it, set basePath to match the route, export the noindex metadata from next-sanity/studio and keep SanityLive out of the Studio layout.

How do I verify Sanity webhooks in a Next.js Route Handler?

Use parseBody from next-sanity/webhook with the same secret you set on the webhook in Sanity, stored as SANITY_REVALIDATE_SECRET. It checks the sanity-webhook-signature header against the raw body and returns isValidSignature and the parsed body. Return 401 when the signature is false or null. By default parseBody waits 3 seconds so the Content Lake has caught up, and Sanity retries a failed delivery only twice, 30 seconds apart.

How much does Sanity cost for a Next.js marketing site?

A small site can run on the free plan: 20 seats, 10,000 documents, 250,000 API requests and 1 million CDN requests a month, with no overage allowed. The Growth plan costs $15 per seat a month and adds paid overage, private datasets and 25,000 documents. The jumps to watch are the $299 a month increased quota add-on and $999 for each extra dataset, according to Sanity's pricing page in November 2026.

Sources

  1. next-sanity README Sanity on GitHub, 2026
  2. Add live content to your application Sanity, 2026
  3. Live content in Next.js Sanity, 2026
  4. Caching and revalidation in Next.js Sanity, 2026
  5. Configuring the Sanity client for Next.js Sanity, 2026
  6. Embed Sanity Studio in Next.js Sanity, 2026
  7. Revalidate Next.js pages with Sanity webhooks Sanity, 2026
  8. Visual Editing with Next.js App Router Sanity, 2026
  9. GROQ-powered webhooks Sanity, 2026
  10. Technical limits Sanity, 2026
  11. Getting started with the JavaScript client Sanity, 2026
  12. Sanity pricing Sanity, 2026
  13. revalidateTag Next.js, 2026
  14. Vercel pricing Vercel, 2026

Tags

  • Next.js
  • Sanity
  • Headless CMS
  • Integrations
Mihajlo Stojanovic

Mihajlo Stojanovic

Co-founder, Octo Agency

Mihajlo runs the technical side of Octo Agency: Webflow builds, custom backends and the systems that keep a site editable after launch. He has shipped more than twenty Webflow sites a year as a white-label partner and writes about what survives contact with a real marketing team.

Veljko Nikolic

Reviewed by

Veljko Nikolic

Founder, Octo Agency

Veljko runs the build side of Octo Agency. He has shipped marketing sites for B2B teams in legal tech, health and manufacturing, and writes about what survives contact with a real review cycle.