From 644d1df58546dfb941df47b92fac2fe1e72afdc0 Mon Sep 17 00:00:00 2001 From: SimeonGriggs Date: Fri, 18 Oct 2024 16:34:34 +0100 Subject: [PATCH 1/3] feat: prepare nextjs starter template for live mode --- .../cli/src/actions/init-project/templates/nextjs/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts b/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts index bfbdd0c6b4b..112142ab879 100644 --- a/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts +++ b/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts @@ -165,6 +165,12 @@ export const client = createClient({ }) ` +const live = `import { defineLive } from "next-sanity"; +import { client } from './client' + +export const { sanityFetch, SanityLive } = defineLive({ client }); +` + const imageTS = `import createImageUrlBuilder from '@sanity/image-url' import { SanityImageSource } from "@sanity/image-url/lib/types/types"; @@ -201,6 +207,7 @@ export const sanityFolder = ( 'env.': useTypeScript ? envTS : envJS, 'lib': { 'client.': client, + 'live.': live, 'image.': useTypeScript ? imageTS : imageJS, }, } From ce54d0ea4257def8501894371013ee3f7a57e1a6 Mon Sep 17 00:00:00 2001 From: Simeon Griggs Date: Mon, 28 Oct 2024 23:13:57 +0000 Subject: [PATCH 2/3] Update packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts Add explanation to live.ts Co-authored-by: Espen Hovlandsdal --- .../cli/src/actions/init-project/templates/nextjs/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts b/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts index 112142ab879..b0c9b407afd 100644 --- a/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts +++ b/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts @@ -165,6 +165,9 @@ export const client = createClient({ }) ` +// Importing and querying through `sanityFetch` from this file will make data automatically stay up to date with any changes. +// Before using it, import and render `` in your layout - see +// https://github.com/sanity-io/next-sanity#live-content-api for more information. const live = `import { defineLive } from "next-sanity"; import { client } from './client' From 92333491ef2709b0f9b322d5953baebdf026c2c8 Mon Sep 17 00:00:00 2001 From: SimeonGriggs Date: Tue, 29 Oct 2024 10:24:19 +1030 Subject: [PATCH 3/3] fix: update explanation, set apiVersion --- .../actions/init-project/templates/nextjs/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts b/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts index b0c9b407afd..32eda6e6b42 100644 --- a/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts +++ b/packages/@sanity/cli/src/actions/init-project/templates/nextjs/index.ts @@ -165,13 +165,19 @@ export const client = createClient({ }) ` -// Importing and querying through `sanityFetch` from this file will make data automatically stay up to date with any changes. -// Before using it, import and render `` in your layout - see +const live = `// Querying with "sanityFetch" will keep content automatically updated +// Before using it, import and render "" in your layout, see // https://github.com/sanity-io/next-sanity#live-content-api for more information. -const live = `import { defineLive } from "next-sanity"; +import { defineLive } from "next-sanity"; import { client } from './client' -export const { sanityFetch, SanityLive } = defineLive({ client }); +export const { sanityFetch, SanityLive } = defineLive({ + client: client.withConfig({ + // Live content is currently only available on the experimental API + // https://www.sanity.io/docs/api-versioning + apiVersion: 'vX' + }) +}); ` const imageTS = `import createImageUrlBuilder from '@sanity/image-url'