mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Removes the "allow-runtime" prefetch config, and turns its behavior on implicitly wherever Partial Prefetching is enabled. The original motivation for "allow-runtime" was to give apps more control over server costs triggered by prefetches. Until a route explicitly opts in, prefetches would only be served from the CDN, not from the server. The problem, though, was it was very confusing to know when to add or remove this configuration. The incentive for many apps was to add it everywhere, with no clear signal for when to remove it. Our updated thinking is that Partial Prefetching itself already provides sufficient protection against runaway prefetching costs: per-link prefetches only happen on Link components that explicitly opt in with the prefetch prop. The optimizations landed earlier in this stack also make allow-runtime less necessary: on pages where all the content is statically renderable, prefetches are served from the static cache and no runtime request is ever issued; only a page that accesses non-static data is prefetched at runtime. The upshot of this decision is that runtime versus static becomes an internal optimization; the same content gets prefetched regardless of whether or how Next.js is able to optimize it.
48 lines
995 B
TypeScript
48 lines
995 B
TypeScript
export const instant = true
|
|
export const prefetch = 'partial'
|
|
|
|
export default async function Page() {
|
|
return (
|
|
<main>
|
|
<h1>Warmup Dev Renders - deep successive cache reads</h1>
|
|
<One />
|
|
</main>
|
|
)
|
|
}
|
|
|
|
async function One() {
|
|
const cache1 = await fastCache()
|
|
console.log('after cache 1')
|
|
return <Two cache1={cache1} />
|
|
}
|
|
|
|
async function Two({ cache1 }) {
|
|
const cache2 = await slowCache(1)
|
|
console.log('after cache 2')
|
|
return <Three cache1={cache1} cache2={cache2} />
|
|
}
|
|
|
|
async function Three({ cache1, cache2 }) {
|
|
console.log('after caches 1 and 2')
|
|
const cache3 = await slowCache(2)
|
|
console.log('after cache 3')
|
|
return (
|
|
<div>
|
|
<div>Cache 1: {cache1}</div>
|
|
<div>Cache 2: {cache2}</div>
|
|
<div>Cache 3: {cache3}</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
async function fastCache() {
|
|
'use cache'
|
|
return Math.random()
|
|
}
|
|
|
|
async function slowCache(_key: number) {
|
|
'use cache'
|
|
await new Promise((resolve) => setTimeout(resolve))
|
|
return Math.random()
|
|
}
|