You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### What?
When using a `Request` object with fetch, we'll log a warning indicating that using the `cache` property in addition to `revalidate` is unsupported.
### Why?
`Request` sets some defaults on the request init, such as `cache: "default"`. This makes the warning confusing and there's no way to avoid it aside from switching the resource argument to be a URL string instead.
### How?
This keeps existing behavior but omits the log in the case where a request object is used and no explicit cache overrides are specified.
Fixes#58109
Copy file name to clipboardExpand all lines: packages/next/src/server/lib/patch-fetch.ts
+7-3Lines changed: 7 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -266,9 +266,13 @@ export function patchFetch({
266
266
typeof_cache==='string'&&
267
267
typeofcurRevalidate!=='undefined'
268
268
){
269
-
Log.warn(
270
-
`fetch for ${fetchUrl} on ${staticGenerationStore.urlPathname} specified "cache: ${_cache}" and "revalidate: ${curRevalidate}", only one should be specified.`
271
-
)
269
+
// when providing fetch with a Request input, it'll automatically set a cache value of 'default'
270
+
// we only want to warn if the user is explicitly setting a cache value
271
+
if(!(isRequestInput&&_cache==='default')){
272
+
Log.warn(
273
+
`fetch for ${fetchUrl} on ${staticGenerationStore.urlPathname} specified "cache: ${_cache}" and "revalidate: ${curRevalidate}", only one should be specified.`
// we don't need verbose logging (enabled by default in this Next app) for these tests to work
13
+
// we avoid enabling it since it's not currently compatible with Turbopack.
14
+
awaitnext.stop()
15
+
awaitnext.deleteFile('next.config.js')
16
+
awaitnext.start()
17
+
awaitnext.fetch('/cache-revalidate')
18
+
})
19
+
20
+
it('should log when request input is a string',async()=>{
21
+
awaitcheck(()=>{
22
+
returnnext.cliOutput.includes(
23
+
'fetch for https://next-data-api-endpoint.vercel.app/api/random?request-string on /cache-revalidate specified "cache: force-cache" and "revalidate: 3", only one should be specified'
24
+
)
25
+
? 'success'
26
+
: 'fail'
27
+
},'success')
28
+
})
29
+
30
+
it('should log when request input is a Request instance',async()=>{
31
+
awaitcheck(()=>{
32
+
returnnext.cliOutput.includes(
33
+
'fetch for https://next-data-api-endpoint.vercel.app/api/random?request-input-cache-override on /cache-revalidate specified "cache: force-cache" and "revalidate: 3", only one should be specified.'
34
+
)
35
+
? 'success'
36
+
: 'fail'
37
+
},'success')
38
+
})
39
+
40
+
it('should not log when overriding cache within the Request object',async()=>{
41
+
awaitcheck(()=>{
42
+
returnnext.cliOutput.includes(
43
+
`fetch for https://next-data-api-endpoint.vercel.app/api/random?request-input on /cache-revalidate specified "cache: default" and "revalidate: 3", only one should be specified.`
0 commit comments