next-sanity 4.1.0 → 4.1.2
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 +125 -64
- package/package.json +20 -20
package/README.md
CHANGED
|
@@ -13,20 +13,21 @@
|
|
|
13
13
|
- [Table of contents](#table-of-contents)
|
|
14
14
|
- [Installation](#installation)
|
|
15
15
|
- [`next-sanity` Running groq queries](#next-sanity-running-groq-queries)
|
|
16
|
+
- [`appDir`, React Server Components and caching](#appdir-react-server-components-and-caching)
|
|
16
17
|
- [`next-sanity/preview` Live real-time preview](#next-sanitypreview-live-real-time-preview)
|
|
17
18
|
- [Examples](#examples)
|
|
18
19
|
- [Built-in Sanity auth](#built-in-sanity-auth)
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
20
|
+
- [Using the `/pages` directory](#using-the-pages-directory)
|
|
21
|
+
- [Using the `/app` directory (experimental)](#using-the-app-directory-experimental)
|
|
21
22
|
- [Custom token auth](#custom-token-auth)
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
23
|
+
- [Using the `/pages` directory](#using-the-pages-directory-1)
|
|
24
|
+
- [Using the `/app` directory (experimental)](#using-the-app-directory-experimental-1)
|
|
24
25
|
- [Starters](#starters)
|
|
25
26
|
- [Limits](#limits)
|
|
26
27
|
- [`next-sanity/studio`](#next-sanitystudio)
|
|
27
28
|
- [Usage](#usage)
|
|
28
|
-
- [
|
|
29
|
-
- [
|
|
29
|
+
- [Using the `/app` directory (experimental)](#using-the-app-directory-experimental-2)
|
|
30
|
+
- [Using the `/pages` directory](#using-the-pages-directory-2)
|
|
30
31
|
- [Opt-in to using `StudioProvider` and `StudioLayout`](#opt-in-to-using-studioprovider-and-studiolayout)
|
|
31
32
|
- [`next-sanity/webhook`](#next-sanitywebhook)
|
|
32
33
|
- [Migrate](#migrate)
|
|
@@ -49,10 +50,34 @@
|
|
|
49
50
|
|
|
50
51
|
## Installation
|
|
51
52
|
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
```bash
|
|
54
|
+
npm install next-sanity @portabletext/react @sanity/image-url
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
yarn add next-sanity @portabletext/react @sanity/image-url
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm install next-sanity @portabletext/react @sanity/image-url
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### `next-sanity/studio` peer dependencies
|
|
66
|
+
|
|
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`. For other package managers you may need to do some extra steps.
|
|
68
|
+
|
|
69
|
+
#### Yarn
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx install-peerdeps --yarn next-sanity
|
|
73
|
+
```
|
|
74
|
+
|
|
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
|
|
56
81
|
```
|
|
57
82
|
|
|
58
83
|
## `next-sanity` Running groq queries
|
|
@@ -74,6 +99,34 @@ const client = createClient({
|
|
|
74
99
|
const data = await client.fetch(groq`*[]`)
|
|
75
100
|
```
|
|
76
101
|
|
|
102
|
+
### `appDir`, React Server Components and caching
|
|
103
|
+
|
|
104
|
+
As `@sanity/client` will only sometimes use `fetch` under the hood, it depends on the environment, [it's best to implement the cache function to ensure reliable caching.](https://beta.nextjs.org/docs/data-fetching/caching#per-request-cachingmd)
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import {createClient, groq} from 'next-sanity'
|
|
108
|
+
import {cache} from 'react'
|
|
109
|
+
|
|
110
|
+
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
|
|
111
|
+
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
|
|
112
|
+
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2022-11-16"
|
|
113
|
+
|
|
114
|
+
const client = createClient({
|
|
115
|
+
projectId,
|
|
116
|
+
dataset,
|
|
117
|
+
apiVersion, // https://www.sanity.io/docs/api-versioning
|
|
118
|
+
useCdn: typeof document !== 'undefined', // server-side is statically generated, the CDN is only necessary beneficial if queries are called on-demand
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// Wrap the cache function in a way that reuses the TypeScript definitions
|
|
122
|
+
const clientFetch = cache(client.fetch.bind(client))
|
|
123
|
+
|
|
124
|
+
// Now use it just like before, fully deduped, cached and optimized by react
|
|
125
|
+
const data = await clientFetch(groq`*[]`)
|
|
126
|
+
// You can use the same generics as ebfore
|
|
127
|
+
const total = await clientFetch<number>(groq`count*()`)
|
|
128
|
+
```
|
|
129
|
+
|
|
77
130
|
## `next-sanity/preview` Live real-time preview
|
|
78
131
|
|
|
79
132
|
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).
|
|
@@ -99,7 +152,7 @@ Cons:
|
|
|
99
152
|
- Safari based browsers (Desktop Safari on Macs, and all browsers on iOS) doesn't work.
|
|
100
153
|
- Doesn't support incognito browser modes.
|
|
101
154
|
|
|
102
|
-
`pages/api/preview.
|
|
155
|
+
`pages/api/preview.ts`:
|
|
103
156
|
|
|
104
157
|
```js
|
|
105
158
|
export default function preview(req, res) {
|
|
@@ -109,7 +162,7 @@ export default function preview(req, res) {
|
|
|
109
162
|
}
|
|
110
163
|
```
|
|
111
164
|
|
|
112
|
-
`pages/api/exit-preview.
|
|
165
|
+
`pages/api/exit-preview.ts`:
|
|
113
166
|
|
|
114
167
|
```js
|
|
115
168
|
export default function exit(req, res) {
|
|
@@ -119,9 +172,9 @@ export default function exit(req, res) {
|
|
|
119
172
|
}
|
|
120
173
|
```
|
|
121
174
|
|
|
122
|
-
`components/DocumentsCount.
|
|
175
|
+
`components/DocumentsCount.tsx`:
|
|
123
176
|
|
|
124
|
-
```
|
|
177
|
+
```tsx
|
|
125
178
|
import groq from 'groq'
|
|
126
179
|
|
|
127
180
|
export const query = groq`count(*[])`
|
|
@@ -135,7 +188,7 @@ export function DocumentsCount({data}) {
|
|
|
135
188
|
}
|
|
136
189
|
```
|
|
137
190
|
|
|
138
|
-
`lib/sanity.client.
|
|
191
|
+
`lib/sanity.client.ts`
|
|
139
192
|
|
|
140
193
|
```js
|
|
141
194
|
import {createClient} from 'next-sanity'
|
|
@@ -147,11 +200,9 @@ const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2022-11-16"
|
|
|
147
200
|
export const client = createClient({projectId, dataset, apiVersion, useCdn: false})
|
|
148
201
|
```
|
|
149
202
|
|
|
150
|
-
`lib/sanity.preview.
|
|
203
|
+
`lib/sanity.preview.ts`
|
|
151
204
|
|
|
152
205
|
```js
|
|
153
|
-
'use client'
|
|
154
|
-
|
|
155
206
|
import {definePreview} from 'next-sanity/preview'
|
|
156
207
|
import {projectId, dataset} from 'lib/sanity.client'
|
|
157
208
|
|
|
@@ -161,9 +212,9 @@ function onPublicAccessOnly() {
|
|
|
161
212
|
export const usePreview = definePreview({projectId, dataset, onPublicAccessOnly})
|
|
162
213
|
```
|
|
163
214
|
|
|
164
|
-
`components/PreviewDocumentsCount.
|
|
215
|
+
`components/PreviewDocumentsCount.ts`:
|
|
165
216
|
|
|
166
|
-
```
|
|
217
|
+
```tsx
|
|
167
218
|
'use client'
|
|
168
219
|
|
|
169
220
|
import {usePreview} from 'lib/sanity.preview'
|
|
@@ -175,11 +226,11 @@ export default function PreviewDocumentsCount() {
|
|
|
175
226
|
}
|
|
176
227
|
```
|
|
177
228
|
|
|
178
|
-
#####
|
|
229
|
+
##### Using the `/pages` directory
|
|
179
230
|
|
|
180
|
-
`pages/index.
|
|
231
|
+
`pages/index.tsx`:
|
|
181
232
|
|
|
182
|
-
```
|
|
233
|
+
```tsx
|
|
183
234
|
import {PreviewSuspense} from 'next-sanity/preview'
|
|
184
235
|
import {lazy} from 'react'
|
|
185
236
|
import {DocumentsCount, query} from 'components/DocumentsCount'
|
|
@@ -210,25 +261,31 @@ export default function IndexPage({preview, data}) {
|
|
|
210
261
|
}
|
|
211
262
|
```
|
|
212
263
|
|
|
213
|
-
#####
|
|
264
|
+
##### Using the `/app` directory (experimental)
|
|
214
265
|
|
|
215
|
-
`
|
|
266
|
+
We support the new `appDir` mode in Next, [but please note that `appDir` shouldn't be used in production before Vercel says it's stable](https://beta.nextjs.org/docs/getting-started).
|
|
216
267
|
|
|
217
|
-
|
|
268
|
+
`components/PreviewSuspense.tsx`:
|
|
269
|
+
|
|
270
|
+
```tsx
|
|
218
271
|
'use client'
|
|
219
272
|
|
|
220
273
|
// Once rollup supports 'use client' module directives then 'next-sanity' will include them and this re-export will no longer be necessary
|
|
221
274
|
export {PreviewSuspense as default} from 'next-sanity/preview'
|
|
222
275
|
```
|
|
223
276
|
|
|
224
|
-
`app/page.
|
|
277
|
+
`app/page.tsx`:
|
|
225
278
|
|
|
226
|
-
```
|
|
279
|
+
```tsx
|
|
227
280
|
import {previewData} from 'next/headers'
|
|
228
281
|
import PreviewSuspense from 'components/PreviewSuspense'
|
|
229
282
|
import {DocumentsCount, query} from 'components/DocumentsCount'
|
|
230
283
|
import PreviewDocumentsCount from 'components/PreviewDocumentsCount'
|
|
231
284
|
import {client} from 'lib/sanity.client'
|
|
285
|
+
import {cache} from 'react'
|
|
286
|
+
|
|
287
|
+
// Enable NextJS to cache and dedupe queries
|
|
288
|
+
const clientFetch = cache(client.fetch.bind(client))
|
|
232
289
|
|
|
233
290
|
export default async function IndexPage() {
|
|
234
291
|
if (previewData()) {
|
|
@@ -239,7 +296,7 @@ export default async function IndexPage() {
|
|
|
239
296
|
)
|
|
240
297
|
}
|
|
241
298
|
|
|
242
|
-
const data = await
|
|
299
|
+
const data = await clientFetch(query)
|
|
243
300
|
return <DocumentsCount data={data} />
|
|
244
301
|
}
|
|
245
302
|
```
|
|
@@ -261,7 +318,7 @@ Cons:
|
|
|
261
318
|
- Like all things with great power comes great responsibility. You're responsible for implementing adequate protection against leaking the `token` in your js bundle, or preventing the `/api/preview?secret=${secret}` from being easily guessable.
|
|
262
319
|
- It results in a larger JS bundle as `@sanity/groq-store` currently requires `event-source-polyfill` since native `window.EventSource` does not support setting `Authorization` headers needed for the token auth.
|
|
263
320
|
|
|
264
|
-
`pages/api/preview.
|
|
321
|
+
`pages/api/preview.ts`:
|
|
265
322
|
|
|
266
323
|
```js
|
|
267
324
|
import getSecret from 'lib/getSecret'
|
|
@@ -282,7 +339,7 @@ export default async function preview(req, res) {
|
|
|
282
339
|
}
|
|
283
340
|
```
|
|
284
341
|
|
|
285
|
-
`pages/api/exit-preview.
|
|
342
|
+
`pages/api/exit-preview.ts`:
|
|
286
343
|
|
|
287
344
|
```js
|
|
288
345
|
export default function exit(req, res) {
|
|
@@ -292,9 +349,9 @@ export default function exit(req, res) {
|
|
|
292
349
|
}
|
|
293
350
|
```
|
|
294
351
|
|
|
295
|
-
`components/DocumentsCount.
|
|
352
|
+
`components/DocumentsCount.tsx`:
|
|
296
353
|
|
|
297
|
-
```
|
|
354
|
+
```tsx
|
|
298
355
|
import groq from 'groq'
|
|
299
356
|
|
|
300
357
|
export const query = groq`count(*[])`
|
|
@@ -308,7 +365,7 @@ export function DocumentsCount({data}) {
|
|
|
308
365
|
}
|
|
309
366
|
```
|
|
310
367
|
|
|
311
|
-
`lib/sanity.client.
|
|
368
|
+
`lib/sanity.client.ts`
|
|
312
369
|
|
|
313
370
|
```js
|
|
314
371
|
import {createClient} from 'next-sanity'
|
|
@@ -320,20 +377,18 @@ const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION // "2022-11-16"
|
|
|
320
377
|
export const client = createClient({projectId, dataset, apiVersion, useCdn: false})
|
|
321
378
|
```
|
|
322
379
|
|
|
323
|
-
`lib/sanity.preview.
|
|
380
|
+
`lib/sanity.preview.ts`
|
|
324
381
|
|
|
325
382
|
```js
|
|
326
|
-
'use client'
|
|
327
|
-
|
|
328
383
|
import {definePreview} from 'next-sanity/preview'
|
|
329
384
|
import {projectId, dataset} from 'lib/sanity.client'
|
|
330
385
|
|
|
331
386
|
export const usePreview = definePreview({projectId, dataset})
|
|
332
387
|
```
|
|
333
388
|
|
|
334
|
-
`components/PreviewDocumentsCount.
|
|
389
|
+
`components/PreviewDocumentsCount.tsx`:
|
|
335
390
|
|
|
336
|
-
```
|
|
391
|
+
```tsx
|
|
337
392
|
'use client'
|
|
338
393
|
|
|
339
394
|
import {usePreview} from 'lib/sanity.preview'
|
|
@@ -345,16 +400,17 @@ export default function PreviewDocumentsCount({token}) {
|
|
|
345
400
|
}
|
|
346
401
|
```
|
|
347
402
|
|
|
348
|
-
#####
|
|
403
|
+
##### Using the `/pages` directory
|
|
349
404
|
|
|
350
|
-
`pages/index.
|
|
405
|
+
`pages/index.tsx`:
|
|
351
406
|
|
|
352
|
-
```
|
|
407
|
+
```tsx
|
|
353
408
|
import {PreviewSuspense} from 'next-sanity/preview'
|
|
354
409
|
import {lazy} from 'react'
|
|
355
410
|
import {DocumentsCount, query} from 'components/DocumentsCount'
|
|
356
411
|
import {client} from 'lib/sanity.client'
|
|
357
412
|
|
|
413
|
+
// Wrapping preview components in React.lazy ensures visitors not on preview mode doesn't load any JS related to it
|
|
358
414
|
const PreviewDocumentsCount = lazy(() => import('components/PreviewDocumentsCount'))
|
|
359
415
|
|
|
360
416
|
export const getStaticProps = async ({preview = false, previewData = {}}) => {
|
|
@@ -380,31 +436,34 @@ export default function IndexPage({preview, token, data}) {
|
|
|
380
436
|
}
|
|
381
437
|
```
|
|
382
438
|
|
|
383
|
-
#####
|
|
439
|
+
##### Using the `/app` directory (experimental)
|
|
440
|
+
|
|
441
|
+
We support the new `appDir` mode in Next, [but please note that `appDir` shouldn't be used in production before Vercel says it's stable](https://beta.nextjs.org/docs/getting-started).
|
|
384
442
|
|
|
385
|
-
`components/PreviewSuspense.
|
|
443
|
+
`components/PreviewSuspense.tsx`:
|
|
386
444
|
|
|
387
|
-
```
|
|
445
|
+
```tsx
|
|
388
446
|
'use client'
|
|
389
447
|
|
|
390
448
|
// Once rollup supports 'use client' module directives then 'next-sanity' will include them and this re-export will no longer be necessary
|
|
391
449
|
export {PreviewSuspense as default} from 'next-sanity/preview'
|
|
392
450
|
```
|
|
393
451
|
|
|
394
|
-
`app/page.
|
|
452
|
+
`app/page.tsx`:
|
|
395
453
|
|
|
396
|
-
```
|
|
454
|
+
```tsx
|
|
397
455
|
import {previewData} from 'next/headers'
|
|
398
456
|
import PreviewSuspense from 'components/PreviewSuspense'
|
|
399
457
|
import {DocumentsCount, query} from 'components/DocumentsCount'
|
|
400
458
|
import PreviewDocumentsCount from 'components/PreviewDocumentsCount'
|
|
401
459
|
import {client} from 'lib/sanity.client'
|
|
402
460
|
|
|
461
|
+
type AppPreviewData = {token: string} | undefined
|
|
403
462
|
export default async function IndexPage() {
|
|
404
|
-
if (previewData()?.token) {
|
|
463
|
+
if ((previewData() as AppPreviewData)?.token) {
|
|
405
464
|
return (
|
|
406
465
|
<PreviewSuspense fallback="Loading...">
|
|
407
|
-
<PreviewDocumentsCount token={previewData().token} />
|
|
466
|
+
<PreviewDocumentsCount token={(previewData() as AppPreviewData).token} />
|
|
408
467
|
</PreviewSuspense>
|
|
409
468
|
)
|
|
410
469
|
}
|
|
@@ -456,7 +515,7 @@ The basic setup is 2 components, `NextStudio` and `NextStudioHead`.
|
|
|
456
515
|
`NextStudio` loads up the `import {Studio} from 'sanity'` component for you and wraps it in a Next-friendly layout.
|
|
457
516
|
While `NextStudioHead` sets necessary `<head>` meta tags such as `<meta name="viewport">` to ensure the responsive CSS in the Studio works as expected.
|
|
458
517
|
|
|
459
|
-
Both the Next
|
|
518
|
+
Both the Next `/app` and `/pages` examples uses this config file:
|
|
460
519
|
`sanity.config.ts`:
|
|
461
520
|
|
|
462
521
|
```ts
|
|
@@ -501,9 +560,11 @@ export default defineCliConfig({api: {projectId, dataset}})
|
|
|
501
560
|
|
|
502
561
|
Now you can run commands like `npx sanity cors add`. See `npx sanity help` for a full list of what you can do.
|
|
503
562
|
|
|
504
|
-
####
|
|
563
|
+
#### Using the `/app` directory (experimental)
|
|
564
|
+
|
|
565
|
+
We support the new `appDir` mode in Next, [but please note that `appDir` shouldn't be used in production before Vercel says it's stable](https://beta.nextjs.org/docs/getting-started).
|
|
505
566
|
|
|
506
|
-
In Next 13's `appDir` mode you use `page.tsx` to load `NextStudio`, and optionally (recommended, especially if you want great support for iPhones and other devices with display cutouts like "The Notch" or "Dynamic Island") export `NextStudioHead` in a `head.tsx`.
|
|
567
|
+
In Next 13's new `appDir` mode you use `page.tsx` to load `NextStudio`, and optionally (recommended, especially if you want great support for iPhones and other devices with display cutouts like "The Notch" or "Dynamic Island") export `NextStudioHead` in a `head.tsx`.
|
|
507
568
|
In routes that load `NextStudio` ensure you have `'use client'` at the top of your file.
|
|
508
569
|
|
|
509
570
|
`app/studio/[[...index]]/page.tsx`:
|
|
@@ -560,7 +621,7 @@ export default function Loading() {
|
|
|
560
621
|
}
|
|
561
622
|
```
|
|
562
623
|
|
|
563
|
-
####
|
|
624
|
+
#### Using the `/pages` directory
|
|
564
625
|
|
|
565
626
|
Using just `NextStudio` gives you a fully working Sanity Studio v3. However we recommend also using `NextStudioHead` as it ensures CSS Media Queries that target mobile devices with display cutouts (for example iPhone's "The Notch" and "Dynamic Island") and other details.
|
|
566
627
|
|
|
@@ -651,7 +712,7 @@ The `v3` release only contains breaking changes on the `next-sanity/studio` impo
|
|
|
651
712
|
|
|
652
713
|
#### `NextStudioGlobalStyle` is removed
|
|
653
714
|
|
|
654
|
-
The layout is no longer using global CSS to set the Studio height. The switch to local CSS helps interop between Next
|
|
715
|
+
The layout is no longer using global CSS to set the Studio height. The switch to local CSS helps interop between Next `/pages` and `/app` layouts.
|
|
655
716
|
|
|
656
717
|
#### `ServerStyleSheetDocument` is removed
|
|
657
718
|
|
|
@@ -684,7 +745,7 @@ export default function MyComponent(props: Pick<StudioProps, 'config'>) {
|
|
|
684
745
|
}
|
|
685
746
|
```
|
|
686
747
|
|
|
687
|
-
The reason why `useBasePath` and `useConfigWithBasePath` got removed is because Next
|
|
748
|
+
The reason why `useBasePath` and `useConfigWithBasePath` got removed is because Next `/pages` and `/app` diverge too much in how they declare dynamic segments. Thus you'll need to specify `basePath` in your `sanity.config.ts` manually to match the route you're loading the studio, for the time being.
|
|
688
749
|
|
|
689
750
|
#### The `NextStudioHead` component has moved from `next-sanity/studio` to `next-sanity/studio/head`
|
|
690
751
|
|
|
@@ -698,11 +759,11 @@ There are several differences between the hooks. First of all, `definePreview` r
|
|
|
698
759
|
|
|
699
760
|
##### Before
|
|
700
761
|
|
|
701
|
-
The files that are imported here are the same as the [Next
|
|
762
|
+
The files that are imported here are the same as the [Next `/pages` example](#using-the-pages-director).
|
|
702
763
|
|
|
703
|
-
`pages/index.
|
|
764
|
+
`pages/index.tsx`
|
|
704
765
|
|
|
705
|
-
```
|
|
766
|
+
```tsx
|
|
706
767
|
import {createPreviewSubscriptionHook} from 'next-sanity'
|
|
707
768
|
import {DocumentsCount, query} from 'components/DocumentsCount'
|
|
708
769
|
import {client, projectId, dataset} from 'lib/sanity.client'
|
|
@@ -722,9 +783,9 @@ export default function IndexPage({preview, data: initialData}) {
|
|
|
722
783
|
|
|
723
784
|
##### After
|
|
724
785
|
|
|
725
|
-
`components/PreviewDocumentsCount.
|
|
786
|
+
`components/PreviewDocumentsCount.tsx`
|
|
726
787
|
|
|
727
|
-
```
|
|
788
|
+
```tsx
|
|
728
789
|
import {definePreview} from 'next-sanity/preview'
|
|
729
790
|
import {projectId, dataset} from 'lib/sanity.client'
|
|
730
791
|
|
|
@@ -735,9 +796,9 @@ export default function PreviewDocumentsCount() {
|
|
|
735
796
|
}
|
|
736
797
|
```
|
|
737
798
|
|
|
738
|
-
`pages/index.
|
|
799
|
+
`pages/index.tsx`
|
|
739
800
|
|
|
740
|
-
```
|
|
801
|
+
```tsx
|
|
741
802
|
import {lazy} from 'react'
|
|
742
803
|
import {PreviewSuspense} from 'next-sanity/preview'
|
|
743
804
|
import {DocumentsCount, query} from 'components/DocumentsCount'
|
|
@@ -767,7 +828,7 @@ export default function IndexPage({preview, data}) {
|
|
|
767
828
|
|
|
768
829
|
If you used this hook to check if the user is cookie authenticated:
|
|
769
830
|
|
|
770
|
-
```
|
|
831
|
+
```tsx
|
|
771
832
|
import {createCurrentUserHook} from 'next-sanity'
|
|
772
833
|
|
|
773
834
|
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID
|
|
@@ -784,7 +845,7 @@ export default function Page() {
|
|
|
784
845
|
|
|
785
846
|
Then you can achieve the same functionality using `@sanity/preview-kit` and `suspend-react`:
|
|
786
847
|
|
|
787
|
-
```
|
|
848
|
+
```tsx
|
|
788
849
|
import {suspend} from 'suspend-react'
|
|
789
850
|
import {_checkAuth} from '@sanity/preview-kit'
|
|
790
851
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -147,46 +147,46 @@
|
|
|
147
147
|
},
|
|
148
148
|
"dependencies": {
|
|
149
149
|
"@sanity/client": "^4",
|
|
150
|
-
"@sanity/preview-kit": "^1.
|
|
150
|
+
"@sanity/preview-kit": "^1.3",
|
|
151
151
|
"@sanity/webhook": "^2",
|
|
152
152
|
"groq": "^3"
|
|
153
153
|
},
|
|
154
154
|
"devDependencies": {
|
|
155
155
|
"@rollup/plugin-url": "^8.0.1",
|
|
156
156
|
"@sanity/eslint-config-studio": "^2.0.1",
|
|
157
|
-
"@sanity/image-url": "^1.0.
|
|
158
|
-
"@sanity/pkg-utils": "^2.2.
|
|
159
|
-
"@sanity/semantic-release-preset": "^
|
|
160
|
-
"@sanity/ui": "^1.0
|
|
161
|
-
"@sanity/vision": "^3.2.
|
|
162
|
-
"@types/eventsource": "^1.1.
|
|
163
|
-
"@types/jest": "^29.
|
|
164
|
-
"@types/react": "^18.0.
|
|
157
|
+
"@sanity/image-url": "^1.0.2",
|
|
158
|
+
"@sanity/pkg-utils": "^2.2.3",
|
|
159
|
+
"@sanity/semantic-release-preset": "^4.0.0",
|
|
160
|
+
"@sanity/ui": "^1.1.0",
|
|
161
|
+
"@sanity/vision": "^3.2.5",
|
|
162
|
+
"@types/eventsource": "^1.1.11",
|
|
163
|
+
"@types/jest": "^29.4.0",
|
|
164
|
+
"@types/react": "^18.0.27",
|
|
165
165
|
"@types/react-dom": "^18.0.10",
|
|
166
166
|
"@types/styled-components": "^5.1.26",
|
|
167
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
167
|
+
"@typescript-eslint/eslint-plugin": "^5.49.0",
|
|
168
168
|
"autoprefixer": "^10.4.13",
|
|
169
169
|
"eslint": "^8.32.0",
|
|
170
|
-
"eslint-config-next": "13.1.
|
|
170
|
+
"eslint-config-next": "13.1.5",
|
|
171
171
|
"eslint-config-prettier": "^8.6.0",
|
|
172
172
|
"eslint-config-sanity": "^6.0.0",
|
|
173
173
|
"eslint-gitignore": "^0.1.0",
|
|
174
174
|
"eslint-plugin-prettier": "^4.2.1",
|
|
175
175
|
"eslint-plugin-simple-import-sort": "^9.0.0",
|
|
176
|
-
"groqd": "^0.
|
|
177
|
-
"jest": "^29.
|
|
178
|
-
"jest-environment-jsdom": "^29.
|
|
179
|
-
"ls-engines": "^0.8.
|
|
180
|
-
"next": "13.1.
|
|
176
|
+
"groqd": "^0.5.0",
|
|
177
|
+
"jest": "^29.4.1",
|
|
178
|
+
"jest-environment-jsdom": "^29.4.1",
|
|
179
|
+
"ls-engines": "^0.8.1",
|
|
180
|
+
"next": "13.1.5",
|
|
181
181
|
"postcss": "^8.4.21",
|
|
182
182
|
"prettier": "^2.8.3",
|
|
183
183
|
"prettier-plugin-packagejson": "^2.4.0",
|
|
184
|
-
"prettier-plugin-tailwindcss": "^0.2.
|
|
184
|
+
"prettier-plugin-tailwindcss": "^0.2.2",
|
|
185
185
|
"react": "^18.2.0",
|
|
186
186
|
"react-dom": "^18.2.0",
|
|
187
187
|
"react-is": "^18.2.0",
|
|
188
|
-
"rollup": "^3.
|
|
189
|
-
"sanity": "^3.2.
|
|
188
|
+
"rollup": "^3.11.0",
|
|
189
|
+
"sanity": "^3.2.5",
|
|
190
190
|
"styled-components": "^5.3.6",
|
|
191
191
|
"tailwindcss": "^3.2.4",
|
|
192
192
|
"typescript": "^4.9.4",
|