mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
If a user creates a custom fetch implementation in module scope, the logic to preload entries during `next start` will result in fetch not being patched before the userland implementation. As a result, it won't opt into any caching heuristics from our patched fetch. Fixes #71881 (in addition to the other PR in this stack)
37 lines
780 B
JavaScript
37 lines
780 B
JavaScript
import { cookies } from 'next/headers'
|
|
import { Suspense } from 'react'
|
|
|
|
const patchFetch = (originalFetch) => async (url, options) => {
|
|
const res = await originalFetch(url, options)
|
|
return res
|
|
}
|
|
|
|
const customFetch = patchFetch(fetch)
|
|
|
|
export default async function Page() {
|
|
const data = await customFetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?revalidate-3',
|
|
{
|
|
next: {
|
|
revalidate: 3,
|
|
},
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
return (
|
|
<>
|
|
<div id="random">{data}</div>
|
|
<Suspense fallback={<div>Loading...</div>}>
|
|
<DynamicThing />
|
|
</Suspense>
|
|
</>
|
|
)
|
|
}
|
|
|
|
async function DynamicThing() {
|
|
const cookieStore = await cookies()
|
|
const cookie = cookieStore.get('name')
|
|
|
|
return <div>{cookie}</div>
|
|
}
|