diff --git a/packages/next/src/server/lib/patch-fetch.ts b/packages/next/src/server/lib/patch-fetch.ts index 9f4d499a111da..4a831e9788151 100644 --- a/packages/next/src/server/lib/patch-fetch.ts +++ b/packages/next/src/server/lib/patch-fetch.ts @@ -266,9 +266,13 @@ export function patchFetch({ typeof _cache === 'string' && typeof curRevalidate !== 'undefined' ) { - Log.warn( - `fetch for ${fetchUrl} on ${staticGenerationStore.urlPathname} specified "cache: ${_cache}" and "revalidate: ${curRevalidate}", only one should be specified.` - ) + // when providing fetch with a Request input, it'll automatically set a cache value of 'default' + // we only want to warn if the user is explicitly setting a cache value + if (!(isRequestInput && _cache === 'default')) { + Log.warn( + `fetch for ${fetchUrl} on ${staticGenerationStore.urlPathname} specified "cache: ${_cache}" and "revalidate: ${curRevalidate}", only one should be specified.` + ) + } _cache = undefined } diff --git a/test/e2e/app-dir/logging/app/default-cache/page.js b/test/e2e/app-dir/logging/app/default-cache/page.js index aee6e7fdabf6f..af2deb21cc68a 100644 --- a/test/e2e/app-dir/logging/app/default-cache/page.js +++ b/test/e2e/app-dir/logging/app/default-cache/page.js @@ -47,6 +47,32 @@ export default async function Page() { 'https://next-data-api-endpoint.vercel.app/api/random?auto-cache' ).then((res) => res.text()) + // the following fetch requests aren't rendered in UI, just asserted on in server logs + 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, + }, + } + ) + return ( <>

/force-cache

diff --git a/test/e2e/app-dir/logging/index.test.ts b/test/e2e/app-dir/logging/index.test.ts index f3b81958a758b..9adb482068100 100644 --- a/test/e2e/app-dir/logging/index.test.ts +++ b/test/e2e/app-dir/logging/index.test.ts @@ -164,6 +164,41 @@ createNextDescribe( }, /success/) }) } + + describe('cache + revalidate warning', () => { + beforeAll(async () => { + await next.fetch('/default-cache') + }) + 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?revalidate-3-force-cache on /default-cache 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 /default-cache 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 /default-cache specified "cache: default" and "revalidate: 3", only one should be specified.` + ) + ? 'fail' + : 'success' + }, 'success') + }) + }) } describe('with verbose logging', () => {