Integrations · CMS

Sanity with Next.js and Astro, set up for editors

Sanity gives editors a studio shaped around your content, and developers a typed query language. A Next.js Sanity setup, or Sanity on Astro, connects both sides so marketing can publish without a ticket.

Next.js

Next.js and Sanity, step by step

Next.js connects to Sanity through next-sanity; keep read tokens on the server and mount Studio at /studio in the same project.

  1. 01

    Create the project

    Create the Next.js app and a Sanity project with its dataset.

  2. 02

    Mount Studio at /studio

    Add Sanity Studio to the project as a route, so it deploys with the site.

  3. 03

    Set the environment variables

    Project ID and dataset can be public; the read token for drafts stays on the server.

  4. 04

    Configure the client

    Set up the next-sanity client and typed GROQ queries for each page type.

  5. 05

    Add Draft Mode and visual editing

    Editors preview drafts on the real page and click an element to open the field behind it.

Use cases

What teams use it for

01

Marketing site with page building

Editors assemble pages from predefined sections without breaking the design system.

02

Shared content across products

One source for docs, blog, changelog and in-app content, each rendered by its own front-end.

03

Collaborative publishing

Several editors working on the same document at once, with history and scheduled releases.

Cautions

Common Next.js Sanity pitfalls

A token in a NEXT_PUBLIC_ variable ships to every visitor’s browser. Draft read tokens belong in server-only variables.

Security

Missing environment variables on the host break the deploy or the preview. We set them per environment and check them before launch.

Data

Studio’s styles can clash with the site’s CSS when both share a layout. We give Studio its own route and layout.

Performance

A flexible schema invites inconsistency. We add validation rules and limit which section types editors can use per page.

Data

Live queries from every visitor add latency and cost. We use the CDN, build-time fetching or cached server rendering where possible.

Performance
Handover

What we set up and hand over

Next.js builds run on the Development plan, $8,000 a month, or $12,000 with design.

What we set up
Content model, Studio, GROQ queries, visual editing, webhooks
Typical time
1–3 weeks
Complexity
High
FAQ

Questions about Sanity

How do I connect Sanity to Next.js?
With next-sanity, Sanity’s toolkit for the App Router. It covers typed GROQ queries, Draft Mode, visual editing and live content.
Can Sanity Studio live inside our Next.js or Astro site?
Yes. With the official Astro integration or next-sanity, the Studio can be mounted at a route like /studio in the same project and deployed with the site.
Does Sanity support visual editing on Next.js?
Yes. With next-sanity, editors see a live preview and can click an element to open the field behind it. Astro supports previews through Sanity’s integration as well.
Why Sanity instead of the Webflow or Framer CMS?
Sanity is for content that needs custom structure, many editors or several front-ends. For a single marketing site, the Framer or Webflow CMS is usually simpler and enough.
How long does a Sanity integration take?
1–3 weeks, including the content model, Studio and previews.
Thomas OldenburgerFounder, design and build lead

Still deciding? A 30-minute call answers most of it.

Got a brief, or half of one?

Book a free 30-minute call. You leave with a straight answer on scope, price and timing, even when we are not the right fit.