Files
next.js/test/e2e/app-dir/instant-validation-build/app/(default)/gsp/[slug]/page.tsx
T
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

67 lines
1.6 KiB
TypeScript

import type { Instant } from 'next'
import assert from 'node:assert/strict'
import { cookies } from 'next/headers'
import { Suspense } from 'react'
import { AssertParamsClient } from './client'
// samples use 'hello', but generateStaticParams uses 'foo'/'bar'.
// During validation, the sample params should be used, not the GSP values.
export const instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
params: {
slug: 'hello',
},
},
],
}
export const prefetch = 'partial'
export function generateStaticParams() {
return [{ slug: 'foo' }, { slug: 'bar' }]
}
export default async function Page({
params,
}: {
params: Promise<Record<string, string>>
}) {
return (
<main>
<Suspense fallback={<div>Loading...</div>}>
<AssertSampleParams params={params} />
</Suspense>
</main>
)
}
async function AssertSampleParams({
params,
}: {
params: Promise<Record<string, string>>
}) {
// Gate behind cookies() so this subtree is only reachable during
// instant validation (not during regular GSP prerenders, where
// cookies() creates a dynamic hole and defers the Suspense boundary).
await cookies()
const p = await params
// During validation, the param value should come from the sample ('hello'),
// not from generateStaticParams ('foo' or 'bar').
assert.equal(
p.slug,
'hello',
`Expected param 'slug' to be 'hello' (from sample), got '${p.slug}'`
)
// Client component rendered after the cookies() gate, so it also
// only runs during validation.
return (
<>
<div id="slug">{p.slug}</div>
<AssertParamsClient />
</>
)
}