next-sanity 5.5.2 → 5.5.3
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 +10 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -463,7 +463,7 @@ The [same is true][preview-kit-livequery] for `next-sanity/preview/live-query`.
|
|
|
463
463
|
|
|
464
464
|
### Using `draftMode()` to de/activate previews
|
|
465
465
|
|
|
466
|
-
Next.js gives you [a built-in `draftMode` variable][draft-mode] that can
|
|
466
|
+
Next.js gives you [a built-in `draftMode` variable][draft-mode] that can activate features like Visual Edit or any preview implementation.
|
|
467
467
|
|
|
468
468
|
```ts
|
|
469
469
|
// ./src/utils/sanity/client.ts
|
|
@@ -505,20 +505,25 @@ export async function sanityFetch<QueryResponse>({
|
|
|
505
505
|
throw new Error('The `SANITY_API_READ_TOKEN` environment variable is required.')
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
+
const REVALIDATE_SKIP_CACHE = 0
|
|
509
|
+
const REVALIDATE_CACHE_FOREVER = false
|
|
510
|
+
|
|
508
511
|
return client.fetch<QueryResponse>(query, params, {
|
|
509
|
-
cache: 'force-cache',
|
|
510
512
|
...(isDraftMode && {
|
|
511
|
-
cache: undefined,
|
|
512
513
|
token: token,
|
|
513
514
|
perspective: 'previewDrafts',
|
|
514
515
|
}),
|
|
515
516
|
next: {
|
|
516
|
-
|
|
517
|
+
revalidate: isDraftMode ? REVALIDATE_SKIP_CACHE : REVALIDATE_CACHE_FOREVER,
|
|
517
518
|
tags,
|
|
518
519
|
},
|
|
519
520
|
})
|
|
520
521
|
}
|
|
521
522
|
```
|
|
523
|
+
#### Using `cache` and `revalidation` at the same time
|
|
524
|
+
|
|
525
|
+
Be aware that you can get errors if you use the `cache` and the `revalidate` configurations for Next.js cache at the same time. Go to [the Next.js docs][next-revalidate-docs] to learn more.
|
|
526
|
+
|
|
522
527
|
|
|
523
528
|
## Visual Editing with Content Source Maps
|
|
524
529
|
|
|
@@ -745,6 +750,7 @@ MIT-licensed. See [LICENSE][LICENSE].
|
|
|
745
750
|
[next-cache]: https://nextjs.org/docs/app/building-your-application/caching
|
|
746
751
|
[next-data-fetching]: https://nextjs.org/docs/basic-features/data-fetching/overview
|
|
747
752
|
[next-preview-mode]: https://nextjs.org/docs/advanced-features/preview-mode
|
|
753
|
+
[next-revalidate-docs]: https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnextrevalidate
|
|
748
754
|
[pages-router]: https://nextjs.org/docs/pages/building-your-application/routing
|
|
749
755
|
[personal-website-template]: https://github.com/sanity-io/sanity-template-nextjs-app-router-personal-website
|
|
750
756
|
[perspectives-docs]: https://www.sanity.io/docs/perspectives?utm_source=github&utm_medium=readme&utm_campaign=next-sanity
|