mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What? Add `url` property to response returned from patched fetch ### Why? So that libraries that rely on `response.url` work with the app directory and fetch cacheing ### How? Using the same code as https://github.com/vercel/edge-runtime/blob/edge-runtime%402.4.3/packages/primitives/src/primitives/fetch.js#L164 fixes #51642 Co-authored-by: JJ Kasper <[email protected]>
27 lines
874 B
JavaScript
27 lines
874 B
JavaScript
export const fetchCache = 'default-cache'
|
|
|
|
export default async function Page() {
|
|
const [urlDefaultCache, valueDefaultCache] = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?a1'
|
|
).then((res) => Promise.all([res.url, res.text()]))
|
|
|
|
const urlNoCache = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?b2',
|
|
{ cache: 'no-store' }
|
|
).then((res) => res.url)
|
|
|
|
const [urlCached, valueCached] = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?a1'
|
|
).then((res) => Promise.all([res.url, res.text()]))
|
|
|
|
return (
|
|
<>
|
|
<p id="data-url-default-cache">{urlDefaultCache}</p>
|
|
<p id="data-value-default-cache">{valueDefaultCache}</p>
|
|
<p id="data-url-no-cache">{urlNoCache}</p>
|
|
<p id="data-url-cached">{urlCached}</p>
|
|
<p id="data-value-cached">{valueCached}</p>
|
|
</>
|
|
)
|
|
}
|