next-sanity 4.3.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
- [Installation](#installation)
|
|
15
15
|
- [`next-sanity` Running groq queries](#next-sanity-running-groq-queries)
|
|
16
16
|
- [`appDir`, React Server Components and caching](#appdir-react-server-components-and-caching)
|
|
17
|
+
- [`next-sanity` Visual Editing with Content Source Maps](#next-sanity-visual-editing-with-content-source-maps)
|
|
17
18
|
- [`next-sanity/preview` Live real-time preview](#next-sanitypreview-live-real-time-preview)
|
|
18
19
|
- [Examples](#examples)
|
|
19
20
|
- [Built-in Sanity auth](#built-in-sanity-auth)
|
|
@@ -64,22 +65,12 @@ pnpm install next-sanity @portabletext/react @sanity/image-url
|
|
|
64
65
|
|
|
65
66
|
### `next-sanity/studio` peer dependencies
|
|
66
67
|
|
|
67
|
-
When using `npm` newer than `v7` you should end up with needed dependencies like `sanity` and `styled-components` when you `npm install next-sanity`.
|
|
68
|
-
|
|
69
|
-
#### Yarn
|
|
68
|
+
When using `npm` newer than `v7`, or `pnpm` newer than `v8`, you should end up with needed dependencies like `sanity` and `styled-components` when you `npm install next-sanity`. It also works in `yarn` `v1` using `install-peerdeps`:
|
|
70
69
|
|
|
71
70
|
```bash
|
|
72
71
|
npx install-peerdeps --yarn next-sanity
|
|
73
72
|
```
|
|
74
73
|
|
|
75
|
-
#### pnpm
|
|
76
|
-
|
|
77
|
-
You can either setup [`auto-install-peers`](https://stackoverflow.com/questions/72468635/pnpm-peer-dependencies-auto-install/74835069#74835069) and `pnpm install next-sanity` is enough, or:
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
npx install-peerdeps --pnpm next-sanity
|
|
81
|
-
```
|
|
82
|
-
|
|
83
74
|
## `next-sanity` Running groq queries
|
|
84
75
|
|
|
85
76
|
```ts
|
|
@@ -87,7 +78,7 @@ import {createClient, groq} from 'next-sanity'
|
|
|
87
78
|
|
|
88
79
|
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
|
|
89
80
|
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
|
|
90
|
-
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "
|
|
81
|
+
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
|
|
91
82
|
|
|
92
83
|
const client = createClient({
|
|
93
84
|
projectId,
|
|
@@ -109,7 +100,7 @@ import {cache} from 'react'
|
|
|
109
100
|
|
|
110
101
|
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
|
|
111
102
|
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
|
|
112
|
-
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "
|
|
103
|
+
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
|
|
113
104
|
|
|
114
105
|
const client = createClient({
|
|
115
106
|
projectId,
|
|
@@ -127,6 +118,33 @@ const data = await clientFetch(groq`*[]`)
|
|
|
127
118
|
const total = await clientFetch<number>(groq`count*()`)
|
|
128
119
|
```
|
|
129
120
|
|
|
121
|
+
## `next-sanity` Visual Editing with Content Source Maps
|
|
122
|
+
|
|
123
|
+
> **Note**
|
|
124
|
+
>
|
|
125
|
+
> [Content Source Maps][content-source-maps-intro] are available [as an API][content-source-maps] for select [Sanity enterprise customers][enterprise-cta]. [Contact our sales team for more information.][sales-cta]
|
|
126
|
+
|
|
127
|
+
The `createClient` method in `next-sanity` supports [visual editing][visual-editing-intro], it supports all the same options as [`@sanity/preview-kit/client`][preview-kit-client]. Add `studioUrl` to your client configuration and it'll automatically show up on Vercel Preview Deployments:
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
import {createClient, groq} from 'next-sanity'
|
|
131
|
+
|
|
132
|
+
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
|
|
133
|
+
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
|
|
134
|
+
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
|
|
135
|
+
|
|
136
|
+
const client = createClient({
|
|
137
|
+
projectId,
|
|
138
|
+
dataset,
|
|
139
|
+
apiVersion, // https://www.sanity.io/docs/api-versioning
|
|
140
|
+
useCdn: true, // if you're using ISR or only static generation at build time then you can set this to `false` to guarantee no stale content
|
|
141
|
+
studioUrl: '/studio', // Or: 'https://my-cool-project.sanity.studio'
|
|
142
|
+
encodeSourceMap: true, // Optional. Default to: process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview',
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
[Our setup guide walks you through how to customize the experience.][visual-editing]
|
|
147
|
+
|
|
130
148
|
## `next-sanity/preview` Live real-time preview
|
|
131
149
|
|
|
132
150
|
You can implement real-time client side preview using `definePreview`. It works by streaming the whole dataset to the browser, which it keeps updated using [listeners](https://www.sanity.io/docs/realtime-updates) and Mendoza patches. When it receives updates, then the query is run against the client-side datastore using [groq-js](https://github.com/sanity-io/groq-js).
|
|
@@ -195,7 +213,7 @@ import {createClient} from 'next-sanity'
|
|
|
195
213
|
|
|
196
214
|
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
|
|
197
215
|
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
|
|
198
|
-
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "
|
|
216
|
+
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
|
|
199
217
|
|
|
200
218
|
export const client = createClient({projectId, dataset, apiVersion})
|
|
201
219
|
```
|
|
@@ -372,7 +390,7 @@ import {createClient} from 'next-sanity'
|
|
|
372
390
|
|
|
373
391
|
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
|
|
374
392
|
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
|
|
375
|
-
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "
|
|
393
|
+
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2023-05-03"
|
|
376
394
|
|
|
377
395
|
export const client = createClient({projectId, dataset, apiVersion})
|
|
378
396
|
```
|
|
@@ -897,3 +915,11 @@ Semantic release will only release on configured branches, so it is safe to run
|
|
|
897
915
|
## License
|
|
898
916
|
|
|
899
917
|
MIT-licensed. See [LICENSE](LICENSE).
|
|
918
|
+
|
|
919
|
+
[visual-editing]: https://www.sanity.io/docs/vercel-visual-editing?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
920
|
+
[visual-editing-intro]: https://www.sanity.io/blog/visual-editing-sanity-vercel?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
921
|
+
[content-source-maps]: https://www.sanity.io/docs/content-source-maps?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
922
|
+
[content-source-maps-intro]: https://www.sanity.io/blog/content-source-maps-announce?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
923
|
+
[preview-kit-client]: https://github.com/sanity-io/preview-kit#sanitypreview-kitclient
|
|
924
|
+
[sales-cta]: https://www.sanity.io/contact/sales?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
925
|
+
[enterprise-cta]: https://www.sanity.io/enterprise?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|