-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak cache + revalidate fetch warning (#58505)
### 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
- Loading branch information
Showing
4 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export const fetchCache = 'default-cache' | ||
|
||
export default async function Page() { | ||
await fetch( | ||
new Request( | ||
'https://next-data-api-endpoint.vercel.app/api/random?request-input' | ||
), | ||
{ | ||
next: { | ||
revalidate: 3, | ||
}, | ||
} | ||
) | ||
|
||
await fetch( | ||
new Request( | ||
'https://next-data-api-endpoint.vercel.app/api/random?request-input-cache-override', | ||
{ | ||
cache: 'force-cache', | ||
} | ||
), | ||
{ | ||
next: { | ||
revalidate: 3, | ||
}, | ||
} | ||
) | ||
|
||
await fetch( | ||
'https://next-data-api-endpoint.vercel.app/api/random?request-string', | ||
{ | ||
next: { | ||
revalidate: 3, | ||
}, | ||
cache: 'force-cache', | ||
} | ||
) | ||
|
||
return <div>Hello World!</div> | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { check } from 'next-test-utils' | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'app-dir - fetch warnings', | ||
{ | ||
skipDeployment: true, | ||
files: __dirname, | ||
}, | ||
({ next }) => { | ||
beforeAll(async () => { | ||
// we don't need verbose logging (enabled by default in this Next app) for these tests to work | ||
// we avoid enabling it since it's not currently compatible with Turbopack. | ||
await next.stop() | ||
await next.deleteFile('next.config.js') | ||
await next.start() | ||
await next.fetch('/cache-revalidate') | ||
}) | ||
|
||
it('should log when request input is a string', async () => { | ||
await check(() => { | ||
return next.cliOutput.includes( | ||
'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' | ||
) | ||
? 'success' | ||
: 'fail' | ||
}, 'success') | ||
}) | ||
|
||
it('should log when request input is a Request instance', async () => { | ||
await check(() => { | ||
return next.cliOutput.includes( | ||
'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.' | ||
) | ||
? 'success' | ||
: 'fail' | ||
}, 'success') | ||
}) | ||
|
||
it('should not log when overriding cache within the Request object', async () => { | ||
await check(() => { | ||
return next.cliOutput.includes( | ||
`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.` | ||
) | ||
? 'fail' | ||
: 'success' | ||
}, 'success') | ||
}) | ||
} | ||
) |