Unverified Commit b7f51075 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix: respect init.cache if fetch input is request instance (#60821)

When there’s a request input instance and init object present the same
time, we should respect init as preferred

Closes NEXT-2149
parent 752c15e7
...@@ -236,8 +236,9 @@ export function patchFetch({ ...@@ -236,8 +236,9 @@ export function patchFetch({
typeof (input as Request).method === 'string' typeof (input as Request).method === 'string'
const getRequestMeta = (field: string) => { const getRequestMeta = (field: string) => {
let value = isRequestInput ? (input as any)[field] : null // If request input is present but init is not, retrieve from input first.
return value || (init as any)?.[field] const value = (init as any)?.[field]
return value || (isRequestInput ? (input as any)[field] : null)
} }
// If the staticGenerationStore is not available, we can't do any // If the staticGenerationStore is not available, we can't do any
......
export default async function Page() {
await fetch(
new Request(
'https://next-data-api-endpoint.vercel.app/api/random?request-input'
),
{
cache: 'no-store',
}
)
return <div>Hello World!</div>
}
...@@ -141,6 +141,16 @@ createNextDescribe( ...@@ -141,6 +141,16 @@ createNextDescribe(
expect(output).toContain('Cache missed reason: (noStore call)') expect(output).toContain('Cache missed reason: (noStore call)')
}) })
}) })
it('should respect request.init.cache when use with fetch input is instance', async () => {
const logLength = next.cliOutput.length
await next.fetch('/fetch-no-store')
await retry(() => {
const output = stripAnsi(next.cliOutput.slice(logLength))
expect(output).toContain('Cache missed reason: (cache: no-store)')
})
})
} }
} else { } else {
// No fetches logging enabled // No fetches logging enabled
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment