mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This modifies the patched fetch implementation to better handle when called within an `unstable_cache` callback. In these callbacks, it should not throw an error related to dynamic access. This replaces the verbose `trackDynamicFetch` instead with `markCurrentScopeAsDynamic` which already has support for checking if inside an unstable cache context. It also has been adjusted to be a no-op when `export const dynamic = "force-static"`, further simplifying the code within the patch fetch implementation.
30 lines
592 B
React
30 lines
592 B
React
import { unstable_cache } from 'next/cache'
|
|
import { Suspense } from 'react'
|
|
|
|
const getData = unstable_cache(
|
|
async (cache) => {
|
|
const res = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random',
|
|
{ cache }
|
|
)
|
|
|
|
return res.text()
|
|
},
|
|
undefined,
|
|
{}
|
|
)
|
|
|
|
async function Data({ cache = undefined }) {
|
|
const data = await getData(cache)
|
|
|
|
return <div id="data">{data}</div>
|
|
}
|
|
|
|
export default function Page({ cache = undefined }) {
|
|
return (
|
|
<Suspense fallback={<div id="loading">Loading...</div>}>
|
|
<Data cache={cache} />
|
|
</Suspense>
|
|
)
|
|
}
|