next-sanity 5.4.1 → 5.4.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
CHANGED
|
@@ -87,13 +87,15 @@ And it makes sense to set `useCdn` to `false` when:
|
|
|
87
87
|
|
|
88
88
|
### `app-router`, React Server Components and caching
|
|
89
89
|
|
|
90
|
-
>
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
> **Note**
|
|
91
|
+
>
|
|
92
|
+
> [`@sanity/client` now fully supports `fetch` based features](https://github.com/sanity-io/client#nextjs-app-router), [including the new `revalidateTag` API](https://nextjs.org/docs/app/api-reference/functions/revalidateTag). Using `React.cache` is unnecessary.
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
|
+
import 'server-only'
|
|
96
|
+
|
|
97
|
+
import type {QueryParams} from '@sanity/client'
|
|
95
98
|
import {createClient, groq} from 'next-sanity'
|
|
96
|
-
import {cache} from 'react'
|
|
97
99
|
|
|
98
100
|
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
|
|
99
101
|
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
|
|
@@ -103,21 +105,61 @@ const client = createClient({
|
|
|
103
105
|
projectId,
|
|
104
106
|
dataset,
|
|
105
107
|
apiVersion, // https://www.sanity.io/docs/api-versioning
|
|
106
|
-
useCdn:
|
|
108
|
+
useCdn: false,
|
|
107
109
|
})
|
|
108
110
|
|
|
109
|
-
//
|
|
110
|
-
const
|
|
111
|
+
// Used by `PreviewProvider`
|
|
112
|
+
export const token = process.env.SANITY_API_READ_TOKEN
|
|
113
|
+
|
|
114
|
+
const DEFAULT_PARAMS = {} as QueryParams
|
|
115
|
+
const DEFAULT_TAGS = [] as string[]
|
|
116
|
+
|
|
117
|
+
export async function sanityFetch<QueryResponse>({
|
|
118
|
+
query,
|
|
119
|
+
params = DEFAULT_PARAMS,
|
|
120
|
+
tags = DEFAULT_TAGS,
|
|
121
|
+
}: {
|
|
122
|
+
query: string
|
|
123
|
+
params?: QueryParams
|
|
124
|
+
tags: string[]
|
|
125
|
+
}): Promise<QueryResponse> {
|
|
126
|
+
const isDraftMode = draftMode().isEnabled
|
|
127
|
+
if (isDraftMode && !token) {
|
|
128
|
+
throw new Error('The `SANITY_API_READ_TOKEN` environment variable is required.')
|
|
129
|
+
}
|
|
111
130
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
return sanityClient.fetch<QueryResponse>(query, params, {
|
|
132
|
+
cache: 'force-cache',
|
|
133
|
+
...(isDraftMode && {
|
|
134
|
+
cache: undefined,
|
|
135
|
+
token: token,
|
|
136
|
+
perspective: 'previewDrafts',
|
|
137
|
+
}),
|
|
138
|
+
next: {
|
|
139
|
+
...(isDraftMode && {revalidate: 30}),
|
|
140
|
+
tags,
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Inside a Server Component data is easily fetched and tagged
|
|
146
|
+
async function HomePageLayout() {
|
|
147
|
+
const data = await sanityFetch<HomePageData>({
|
|
148
|
+
query: groq`*[_type == "home"][0]`,
|
|
149
|
+
// Now calling `revalidateTag('home')` will revalidate this query, and could be done with a simple GROQ webhook
|
|
150
|
+
tags: ['home'],
|
|
151
|
+
})
|
|
117
152
|
|
|
118
|
-
|
|
153
|
+
return (
|
|
154
|
+
<div>
|
|
155
|
+
<h1>{data.title}</h1>
|
|
156
|
+
<PortableText blocks={data.body} />
|
|
157
|
+
</div>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
```
|
|
119
161
|
|
|
120
|
-
|
|
162
|
+
[Checkout our Personal website template to see a feature complete example of how `revalidateTag` is used together with Live Previews.](https://github.com/sanity-io/sanity-template-nextjs-app-router-personal-website)
|
|
121
163
|
|
|
122
164
|
## `next-sanity` Visual Editing with Content Source Maps
|
|
123
165
|
|
|
@@ -154,6 +196,7 @@ Chose a setup guide for the router you're using:
|
|
|
154
196
|
- [`pages-router`](./PREVIEW-pages-router.md)
|
|
155
197
|
|
|
156
198
|
Since `next-sanity/preview` is simply re-exporting `LiveQueryProvider` and `useLiveQuery` from [`@sanity/preview-kit` you'll find advanced usage and comprehensive docs in its README](https://github.com/sanity-io/preview-kit#sanitypreview-kit-1).
|
|
199
|
+
The [same is true](https://github.com/sanity-io/preview-kit#using-the-livequery-wrapper-component-instead-of-the-uselivequery-hook) for `next-sanity/preview/live-query`.
|
|
157
200
|
|
|
158
201
|
## `next-sanity/studio`
|
|
159
202
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.2",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -174,15 +174,15 @@
|
|
|
174
174
|
"singleQuote": true
|
|
175
175
|
},
|
|
176
176
|
"dependencies": {
|
|
177
|
-
"@sanity/preview-kit": "3.1.
|
|
177
|
+
"@sanity/preview-kit": "3.1.3",
|
|
178
178
|
"@sanity/webhook": "2.0.0",
|
|
179
179
|
"groq": "^3.0.0"
|
|
180
180
|
},
|
|
181
181
|
"devDependencies": {
|
|
182
|
-
"@next/bundle-analyzer": "^13.4.
|
|
183
|
-
"@next/eslint-plugin-next": "13.4.
|
|
182
|
+
"@next/bundle-analyzer": "^13.4.18",
|
|
183
|
+
"@next/eslint-plugin-next": "13.4.18",
|
|
184
184
|
"@rollup/plugin-url": "^8.0.1",
|
|
185
|
-
"@sanity/client": "6.4.
|
|
185
|
+
"@sanity/client": "6.4.8",
|
|
186
186
|
"@sanity/eslint-config-studio": "^3.0.0",
|
|
187
187
|
"@sanity/image-url": "^1.0.2",
|
|
188
188
|
"@sanity/pkg-utils": "^2.4.6",
|
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
"jest": "^29.6.2",
|
|
207
207
|
"jest-environment-jsdom": "^29.6.2",
|
|
208
208
|
"ls-engines": "^0.9.0",
|
|
209
|
-
"next": "13.4.
|
|
209
|
+
"next": "13.4.18",
|
|
210
210
|
"postcss": "^8.4.28",
|
|
211
211
|
"prettier": "^3.0.2",
|
|
212
212
|
"prettier-plugin-packagejson": "^2.4.5",
|
|
@@ -224,7 +224,7 @@
|
|
|
224
224
|
"url-loader": "^4.1.1"
|
|
225
225
|
},
|
|
226
226
|
"peerDependencies": {
|
|
227
|
-
"@sanity/client": "^6.4.
|
|
227
|
+
"@sanity/client": "^6.4.8",
|
|
228
228
|
"@sanity/icons": "^2.0.0",
|
|
229
229
|
"@sanity/types": "^3.0.0",
|
|
230
230
|
"@sanity/ui": "^1.0.0",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {createConditionalLiveQuery} from '@sanity/preview-kit/internals/create-conditional-live-query'
|
|
2
|
-
|
|
3
|
-
import ClientComponent from './LiveQueryClientComponent'
|
|
4
|
-
|
|
5
|
-
export type * from '@sanity/preview-kit/live-query'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This is an experimental new API that might have breaking changes in minor versions.
|
|
9
|
-
* @alpha */
|
|
10
|
-
export const LiveQuery = createConditionalLiveQuery({ClientComponent})
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import {lazy} from 'react'
|
|
4
|
-
|
|
5
|
-
// Re-exporting in a file with `use client` ensures the component stays server-only
|
|
6
|
-
// and isn't preloaded in the client bundle, instead it's loaded only on demand.
|
|
7
|
-
|
|
8
|
-
export default lazy(() => import('@sanity/preview-kit/internals/live-query'))
|