|
| 1 | +## Migrate |
| 2 | + |
| 3 | +### The `VisualEditing` export has been moved to `next-sanity/visual-editing` |
| 4 | + |
| 5 | +The export has been moved to support `output: 'static'` builds. `VisualEditing` makes use of Server Actions, and thus it cannot be exposed to the root `'next-sanity'` export without blocking the ability to use features like `import {defineQuery} from 'next-sanity'` on static builds. |
| 6 | + |
| 7 | +```diff |
| 8 | +// src/app/layout.tsx |
| 9 | + |
| 10 | +-import {VisualEditing} from 'next-sanity' |
| 11 | ++import {VisualEditing} from 'next-sanity/visual-editing' |
| 12 | +import {SanityLive} from '@/sanity/lib/live' |
| 13 | + |
| 14 | +export default function RootLayout({children}: {children: React.ReactNode}) { |
| 15 | + return ( |
| 16 | + <html lang="en"> |
| 17 | + <body> |
| 18 | + {children} |
| 19 | + <SanityLive /> |
| 20 | + {(await draftMode()).isEnabled && <VisualEditing />} |
| 21 | + </body> |
| 22 | + </html> |
| 23 | + ) |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +### The `defineLive` export has been moved to `next-sanity/live` |
| 28 | + |
| 29 | +The export has been moved to support `output: 'static'` builds. `defineLive` makes use of Server Actions, and thus it cannot be exposed to the root `'next-sanity'` export without blocking the ability to use features like `import {defineQuery} from 'next-sanity'` on static builds. |
| 30 | + |
| 31 | +```diff |
| 32 | +// src/sanity/lib/live.ts |
| 33 | + |
| 34 | +import {createClient} from 'next-sanity' |
| 35 | +-import {defineLive} from 'next-sanity' |
| 36 | ++import {defineLive} from 'next-sanity/live' |
| 37 | + |
| 38 | +const client = createClient({ |
| 39 | + projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID, |
| 40 | + dataset: process.env.NEXT_PUBLIC_SANITY_DATASET, |
| 41 | + useCdn: true, |
| 42 | + apiVersion: 'v2025-03-04', |
| 43 | + stega: {studioUrl: '/studio'}, |
| 44 | +}) |
| 45 | + |
| 46 | +const token = process.env.SANITY_API_READ_TOKEN |
| 47 | +if (!token) { |
| 48 | + throw new Error('Missing SANITY_API_READ_TOKEN') |
| 49 | +} |
| 50 | + |
| 51 | +export const {sanityFetch, SanityLive} = defineLive({ |
| 52 | + client, |
| 53 | + serverToken: token, |
| 54 | + browserToken: token, |
| 55 | +}) |
| 56 | +``` |
0 commit comments