sanity-visual-editing-setup
Configures Sanity Visual Editing for your front-end framework. Use when setting up live preview or click-to-edit overlays.
When & Why to Use This Skill
This Claude skill automates the end-to-end configuration of Sanity Visual Editing for modern front-end frameworks including Next.js, Remix, Svelte, Nuxt, and Astro. It eliminates the manual complexity of setting up live previews and click-to-edit overlays by automatically detecting the project framework, installing required dependencies, and injecting the necessary Stega and loader configurations. This ensures a seamless 'what-you-see-is-what-you-get' (WYSIWYG) experience for content editors while maintaining clean, performant code for developers.
Use Cases
- Headless CMS Setup: Rapidly enabling real-time visual editing in a headless architecture to bridge the gap between content management and frontend presentation.
- Live Preview Implementation: Automating the setup of Sanity's Presentation Tool to provide content creators with instant feedback as they edit data.
- Framework-Specific Integration: Streamlining the installation of framework-specific loaders (e.g., next-sanity, @sanity/react-loader) and server-side hooks without manual boilerplate writing.
- Stega Configuration: Correctly enabling and configuring Content Source Maps (Stega) to allow 'click-to-edit' functionality directly from the frontend UI to the Sanity Studio.
| name | sanity-visual-editing-setup |
|---|---|
| description | Configures Sanity Visual Editing for your front-end framework. Use when setting up live preview or click-to-edit overlays. |
Visual Editing Setup
This skill inspects the project and installs/configures the necessary packages for Sanity Visual Editing.
Procedure
Detect Framework
- Check
package.jsondependencies. - Identify:
next,react-router,@remix-run/react,svelte,nuxt,astro.
- Check
Install Dependencies
- Next.js:
npm install next-sanity @sanity/client(Ensure v11+ fornext-sanity) - Remix:
npm install @sanity/react-loader @sanity/client @sanity/visual-editing - Svelte:
npm install @sanity/svelte-loader @sanity/client @sanity/visual-editing - Nuxt:
npm install @nuxtjs/sanity - Astro:
npm install @sanity/astro
- Next.js:
Configure Client (Stega)
- Locate the Sanity Client config (e.g.,
sanity/client.ts,lib/sanity.ts). - Update the configuration to include
stega: { enabled: true, studioUrl: '...' }. - Crucial: Ensure
useCdnlogic is correct (usuallyfalsefor live preview).
- Locate the Sanity Client config (e.g.,
Configure Loaders (Framework Specific)
- Next.js: Setup
defineLiveinsanity/lib/live.ts. Add<SanityLive />to layout. - Remix: Setup
loader.server.ts(server-only) andloader.ts(shared). ImplementuseQuery. - Svelte: Setup
hooks.server.ts(createRequestHandler) and+layout.svelte(useLiveMode).
- Next.js: Setup
Verification
- Ask user to run the dev server.
- Check if overlays appear in the Presentation Tool (iframe).