Files
Andrew ClarkandGitHub 3de2d1a213 Unify allow-runtime with Partial Prefetching (#96106)
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.
2026-07-28 11:51:29 -04:00

37 lines
1.3 KiB
TypeScript

import { Suspense } from 'react'
import { cookies } from 'next/headers'
// The Speculative-phase counterpart of app/uses-cookies/page.tsx: the page
// reads cookies directly in the shell stage of every prerender, so the
// route tree prefetch never carries the static-prefetch hint. As a Partial
// Prefetching segment, the page requires runtime-completeness during the
// Speculative phase (which the consuming test enters via a `prefetch={true}`
// link), and with the hint unset the scheduler skips the static attempt
// entirely and issues the runtime prefetch directly. Unlike the uses-cookies
// fixture, the Speculative runtime prefetch RESOLVES the cookies() read, so
// the cookie-derived content itself arrives in the runtime response.
export const prefetch = 'partial'
async function CookieContent() {
const cookieStore = await cookies()
const value = cookieStore.get('testCookie')?.value ?? 'none'
return (
<div id="speculative-cookie-content">{`Speculative-cookies cookie: ${value}`}</div>
)
}
export default function Page() {
return (
<main>
<p id="page-content">Speculative-cookies page shell text</p>
<Suspense
fallback={
<p id="speculative-cookie-loading">Loading speculative cookie...</p>
}
>
<CookieContent />
</Suspense>
</main>
)
}