sanity-visual-editing-setup

Configures Sanity Visual Editing for your front-end framework. Use when setting up live preview or click-to-edit overlays.

⭐37stars🔀3forks📁View on GitHub🕐Updated Dec 18, 2025

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.
namesanity-visual-editing-setup
descriptionConfigures 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

  1. Detect Framework

    • Check package.json dependencies.
    • Identify: next, react-router, @remix-run/react, svelte, nuxt, astro.
  2. Install Dependencies

    • Next.js: npm install next-sanity @sanity/client (Ensure v11+ for next-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
  3. 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 useCdn logic is correct (usually false for live preview).
  4. Configure Loaders (Framework Specific)

    • Next.js: Setup defineLive in sanity/lib/live.ts. Add <SanityLive /> to layout.
    • Remix: Setup loader.server.ts (server-only) and loader.ts (shared). Implement useQuery.
    • Svelte: Setup hooks.server.ts (createRequestHandler) and +layout.svelte (useLiveMode).
  5. Verification

    • Ask user to run the dev server.
    • Check if overlays appear in the Presentation Tool (iframe).