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 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.
- 01
Create the project
Create the Next.js app and a Sanity project with its dataset.
- 02
Mount Studio at /studio
Add Sanity Studio to the project as a route, so it deploys with the site.
- 03
Set the environment variables
Project ID and dataset can be public; the read token for drafts stays on the server.
- 04
Configure the client
Set up the next-sanity client and typed GROQ queries for each page type.
- 05
Add Draft Mode and visual editing
Editors preview drafts on the real page and click an element to open the field behind it.
Sanity integration per platform: Astro, Next.js, Webflow and Framer
The method depends on where your site is built. Here is what we use for Sanity on each platform.
Framer
Framer has its own native CMS, and we would not build a Framer site around Sanity by default. If Sanity must stay the source of truth, we sync documents into Framer CMS collections via a sync plugin or API, and keep the models simple.
Framer development Via APIWebflow
Webflow has a native CMS, so Sanity means keeping two systems in step. When it is needed, a Sanity webhook triggers a sync into Webflow collections through the Webflow CMS API. Rich text and references need careful mapping.
Webflow development Official integrationAstro
Sanity’s official Astro integration configures the client and can embed Sanity Studio as a route in the same project. We query with GROQ at build time for static pages, or on the server for live content, and render Portable Text with your own components.
Astro development Official SDKNext.js
On Next.js we use next-sanity, Sanity’s toolkit for the App Router. It covers typed GROQ queries, Draft Mode, visual editing and live content. Editors click any element on a preview page to jump to the field that controls it.
Next.js developmentWhat teams use it for
Marketing site with page building
Editors assemble pages from predefined sections without breaking the design system.
Shared content across products
One source for docs, blog, changelog and in-app content, each rendered by its own front-end.
Collaborative publishing
Several editors working on the same document at once, with history and scheduled releases.
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.
Missing environment variables on the host break the deploy or the preview. We set them per environment and check them before launch.
Studio’s styles can clash with the site’s CSS when both share a layout. We give Studio its own route and layout.
A flexible schema invites inconsistency. We add validation rules and limit which section types editors can use per page.
Live queries from every visitor add latency and cost. We use the CDN, build-time fetching or cached server rendering where possible.
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
Questions about Sanity
How do I connect Sanity to Next.js?
Can Sanity Studio live inside our Next.js or Astro site?
Does Sanity support visual editing on Next.js?
Why Sanity instead of the Webflow or Framer CMS?
How long does a Sanity integration take?
Thomas OldenburgerFounder, design and build leadStill deciding? A 30-minute call answers most of it.
Related integrations and services
Payload
An open-source, code-first headless CMS written in TypeScript that installs inside a Next.js app.
OpenStoryblok
A headless CMS built around a visual editor and reusable content blocks.
OpenContentful
An enterprise headless CMS with structured content, environments and roles for larger teams.
OpenNext.js development
Next.js builds with a headless CMS and visual editing.
OpenHeadless CMS
Glossary definition.
Open