Visual Editing
The Presentation tool in the Studio shows the site with drafts, lets editors click any text to edit it, and drag blocks to reorder them. It needs a read token on the site.
Turn it on
- Create a token with the Viewer role:
pnpm --filter studio exec sanity tokens add "Preview" --role viewer- Add it to
apps/web/.env, with the address of the Studio:
NUXT_SANITY_API_READ_TOKEN=sk...NUXT_SANITY_STUDIO_URL=http://localhost:3333- Restart the site and open Presentation in the Studio.
How drafts stay private
Visitors never see drafts. The Presentation tool opens /preview/enable with a one-time secret; the site checks the secret with Sanity and sets a preview cookie for that browser only. /preview/disable removes it. Drafts and stega markers are only used in a browser with that cookie.
Production and caching
Cached pages cannot show drafts, so the cache has to be skipped for editors:
- Vercel: one deployment does both. Pages stay cached with ISR for visitors, and
/preview/enablealso sets Vercel's__prerender_bypasscookie, so the editor's browser skips the cache. The bypass token is derived from the read token; seeserver/preview/enable.tsandisrBypassTokeninnuxt.config.ts. - Other hosts (Cloudflare, Node): their cache cannot be skipped for a single visitor, so caching turns off when a read token is set. Use two deployments of
apps/web: the public site without a token, and a preview deployment with it.
Point the Studio at the site
The Studio opens SANITY_STUDIO_PREVIEW_URL. sanity dev reads apps/studio/.env, and sanity deploy also reads apps/studio/.env.production, so keep http://localhost:3000 for local work and put the deployed site in .env.production. The hosted Studio can still preview a local dev server: type its address in the Presentation address bar.
Add the site to the CORS origins of the project, with credentials:
pnpm --filter studio exec sanity cors add https://example.com --credentialsWhere documents appear
apps/studio/presentation/resolve.ts tells the Presentation tool which URLs show a document, so an editor opening a document in Presentation lands on the right page. Update it when you add a document type with its own URL.