Unverified Commit adb29136 authored by Josh Story's avatar Josh Story Committed by GitHub

Stabilize export const prefetch (#94571)

This API is going to ship stable but some options may individually be
marked unstable
parent 409fa64d
......@@ -124,7 +124,7 @@ pub struct NextSegmentConfig {
pub unstable_instant: Option<Span>,
#[turbo_tasks(trace_ignore)]
#[bincode(with_serde)]
pub unstable_prefetch: Option<Span>,
pub prefetch: Option<Span>,
}
#[turbo_tasks::value_impl]
......@@ -565,15 +565,15 @@ pub async fn parse_segment_config_from_source(
.await?;
}
if let Some(span) = config.unstable_prefetch {
if let Some(span) = config.prefetch {
invalid_config(
source,
"unstable_prefetch",
"prefetch",
span,
rcstr!(
"\"unstable_prefetch\" is a route segment config and can only be used when \
the segment is a Server Component module. Remove the \"use client\" \
directive to use this API."
"\"prefetch\" is a route segment config and can only be used when the segment \
is a Server Component module. Remove the \"use client\" directive to use \
this API."
),
None,
IssueSeverity::Error,
......@@ -1004,8 +1004,8 @@ async fn parse_config_value(
"unstable_instant" => {
config.unstable_instant = Some(span);
}
"unstable_prefetch" => {
config.unstable_prefetch = Some(span);
"prefetch" => {
config.prefetch = Some(span);
}
_ => {}
}
......
......@@ -10,17 +10,17 @@ related:
- app/api-reference/file-conventions/route-segment-config/instant
---
The `unstable_prefetch` route segment config controls how a segment is prefetched during client-side navigation. The default (`'auto'`) lets Next.js manage the strategy on your behalf — today that always means a static prefetch. The other options let you declare which prefetch behavior is appropriate for the segment. Use them with care, since they can affect both navigation latency and prefetch cost.
The `prefetch` route segment config controls how a segment is prefetched during client-side navigation. The default (`'auto'`) lets Next.js manage the strategy on your behalf — today that always means a static prefetch. The other options let you declare which prefetch behavior is appropriate for the segment. Use them with care, since they can affect both navigation latency and prefetch cost.
When you do set this export, consider pairing it with [`unstable_instant`](/docs/app/api-reference/file-conventions/route-segment-config/instant) so validation can confirm that navigations to this segment actually produce an instant UI from the prefetched data. This is especially important for runtime prefetching.
> **Good to know**:
>
> - The `unstable_prefetch` export only works when [`cacheComponents`](/docs/app/api-reference/config/next-config-js/cacheComponents) is enabled.
> - `unstable_prefetch` cannot be used when the segment is a Client Component.
> - The `prefetch` export only works when [`cacheComponents`](/docs/app/api-reference/config/next-config-js/cacheComponents) is enabled.
> - `prefetch` cannot be used when the segment is a Client Component.
```tsx filename="layout.tsx | page.tsx" switcher
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Page() {
return <div>...</div>
......@@ -28,7 +28,7 @@ export default function Page() {
```
```jsx filename="layout.js | page.js" switcher
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Page() {
return <div>...</div>
......@@ -52,7 +52,7 @@ Allows Next.js to prefetch this segment at runtime. Today, setting this option c
> **Good to know**: When Next.js runtime-prefetches a segment, all downstream segments are included in the same runtime prefetch request. This means segments deeper in the tree that are configured with `'force-static'` or `'force-disabled'` will still be prefetched as part of the runtime response.
```tsx filename="page.tsx"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
```
### `'force-static'`
......@@ -67,7 +67,7 @@ Never prefetch this segment. The client will not request segment data ahead of n
## Relationship with the `<Link prefetch>` prop
The `unstable_prefetch` segment config and the [`<Link prefetch>` prop](/docs/app/api-reference/components/link#prefetch) control different aspects of prefetching:
The `prefetch` segment config and the [`<Link prefetch>` prop](/docs/app/api-reference/components/link#prefetch) control different aspects of prefetching:
- The **segment config** informs Next.js about a segment's caching characteristics — whether its data can be prefetched statically, is suitable for a runtime prefetch with the user's session, or should be skipped entirely. This applies to the segment regardless of which link points to it.
- The **`<Link prefetch>` prop** reflects the anticipated intent of a specific link on a specific page. A link that users rarely click can be deprioritized with `prefetch={false}`, independent of how the destination segments are configured.
......@@ -79,11 +79,11 @@ In general, both of these are special circumstances. The default behavior — wh
```tsx
type Prefetch = 'auto' | 'force-disabled' | 'force-static' | 'allow-runtime'
export const unstable_prefetch: Prefetch = 'allow-runtime'
export const prefetch: Prefetch = 'allow-runtime'
```
## Version History
| Version | Changes |
| --------- | ------------------------------------------------------------- |
| `v16.x.x` | `unstable_prefetch` export introduced (Cache Components only) |
| Version | Changes |
| --------- | ---------------------------------------------------- |
| `v16.x.x` | `prefetch` export introduced (Cache Components only) |
......@@ -19,7 +19,7 @@ If you are generating a token to talk to a database that itself should be cached
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
async function getCachedData(token: string, userId: string) {
"use cache"
......@@ -37,7 +37,7 @@ export default async function Page({ params }) {
After:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
async function getCachedData(userId: string) {
"use cache"
......@@ -59,7 +59,7 @@ If you require this random value to be unique per Request and an async version o
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
import { generateKeySync } from 'node:crypto'
......@@ -75,7 +75,7 @@ export default async function Page({ params }) {
After:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
import { generateKey } from 'node:crypto'
......@@ -95,7 +95,7 @@ If you require this random value to be unique per Request and an async version o
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({ params }) {
const { sessionId } = await params
......@@ -107,7 +107,7 @@ export default async function Page({ params }) {
After:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
import { connection } from 'next/server'
......
......@@ -23,7 +23,7 @@ If you are using the current time for performance tracking with elapsed time use
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({ params }) {
const { id } = await params
......@@ -39,7 +39,7 @@ export default async function Page({ params }) {
After:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({ params }) {
const { id } = await params
......@@ -61,7 +61,7 @@ If you want to read the time when some cache entry is created (such as when a Ne
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
async function InformationTable({ id }) {
const data = await fetch(urlFrom(id))
......@@ -87,7 +87,7 @@ export default async function Page({ params }) {
After:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
async function InformationTable({ id }) {
'use cache'
......@@ -124,7 +124,7 @@ If you go with this approach you will need to ensure the Client Component which
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
function RelativeTime({ when }) {
return computeTimeAgo(new Date(), when)
......@@ -178,7 +178,7 @@ export function RelativeTime({ when }) {
```
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
import { RelativeTime } from './relative-time'
......@@ -212,7 +212,7 @@ Next.js enforces that it can always produce at least a partially static initial
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
const lastImpressionTime = (await cookies()).get(
......@@ -230,7 +230,7 @@ export default async function Page() {
After:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
import { Suspense } from 'react'
import { connection } from 'next/server'
......
......@@ -23,7 +23,7 @@ If your random value is cacheable, move the `Math.random()` call to a `"use cach
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({ params }) {
const { category } = await params
......@@ -37,7 +37,7 @@ export default async function Page({ params }) {
After:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
async function RandomizedProductsView({ category }) {
'use cache'
......@@ -62,7 +62,7 @@ If you want the random value to be evaluated on each Request precede it with `aw
Before:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({ params }) {
const { category } = await params
......@@ -76,7 +76,7 @@ export default async function Page({ params }) {
After:
```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
import { connection } from 'next/server'
......
......@@ -1303,5 +1303,7 @@
"1302": "Attempted to advance to stage %s but the render is limited to %s",
"1303": "Route \"%s\": A Client Component used \\`%s\\` outside of \\`<Suspense>\\`.\\n\\nThis prevents the route from being prerendered because the value is only available at runtime.\\n\\nWays to fix this:\\n - [stream] Wrap the Client Component in \\`<Suspense fallback={...}>\\`\\n https://nextjs.org/docs/messages/next-prerender-client-hook#wrap-the-client-component-in-suspense",
"1304": "Route \"%s\": A Client Component used \\`%s\\` outside of \\`<Suspense>\\`.\\n\\nThis prevents the route from being prerendered because the value is only available at runtime.\\n\\nWays to fix this:\\n - [stream] Wrap the Client Component in \\`<Suspense fallback={...}>\\`\\n https://nextjs.org/docs/messages/next-prerender-client-hook#wrap-the-client-component-in-suspense\\n - [prerender] If the dynamic params are known, prerender them with \\`generateStaticParams\\`\\n https://nextjs.org/docs/messages/next-prerender-client-hook#prerender-known-dynamic-params",
"1305": "\\`partialPrefetching\\` requires \\`cacheComponents\\` to be enabled. Please update your %s accordingly."
"1305": "\\`partialPrefetching\\` requires \\`cacheComponents\\` to be enabled. Please update your %s accordingly.",
"1306": "Route \"%s\" cannot use \\`export const prefetch = ...\\` without enabling \\`cacheComponents\\`.",
"1307": "\"prefetch\" is a route segment config and can only be used when the segment is a Server Component module. Remove the \"use client\" directive from \"%s\" to use this API."
}
......@@ -712,16 +712,16 @@ export async function getAppPageStaticInfo({
)
}
// Prevent use client and unstable_prefetch in the same file.
if (directives?.has('client') && 'unstable_prefetch' in config) {
// Prevent use client and prefetch in the same file.
if (directives?.has('client') && 'prefetch' in config) {
throw new Error(
`"unstable_prefetch" is a route segment config and can only be used when the segment is a Server Component module. Remove the "use client" directive from "${pageFilePath}" to use this API.`
`"prefetch" is a route segment config and can only be used when the segment is a Server Component module. Remove the "use client" directive from "${pageFilePath}" to use this API.`
)
}
if ('unstable_prefetch' in config && !nextConfig.cacheComponents) {
if ('prefetch' in config && !nextConfig.cacheComponents) {
throw new Error(
`Route "${page}" cannot use \`export const unstable_prefetch = ...\` without enabling \`cacheComponents\`.`
`Route "${page}" cannot use \`export const prefetch = ...\` without enabling \`cacheComponents\`.`
)
}
......
......@@ -150,7 +150,7 @@ const AppSegmentConfigSchema = z.object({
* a runtime request instead of a static one.
* - 'force-disabled' disables prefetching for the segment.
*/
unstable_prefetch: PrefetchSchema.optional(),
prefetch: PrefetchSchema.optional(),
/**
* The stale time for dynamic responses in seconds.
......@@ -202,9 +202,9 @@ export function parseAppSegmentConfig(
message: `Invalid unstable_instant value ${JSON.stringify(ctx.data)} on "${route}", must be \`true\`, \`false\`, or an object. Read more at https://nextjs.org/docs/messages/invalid-instant-configuration`,
}
}
case 'unstable_prefetch': {
case 'prefetch': {
return {
message: `Invalid unstable_prefetch value ${JSON.stringify(ctx.data)} on "${route}", must be "auto", "partial", "unstable_eager", "force-disabled", or "allow-runtime".`,
message: `Invalid prefetch value ${JSON.stringify(ctx.data)} on "${route}", must be "auto", "partial", "unstable_eager", "force-disabled", or "allow-runtime".`,
}
}
case 'unstable_dynamicStaleTime': {
......@@ -278,7 +278,7 @@ export type AppSegmentConfig = {
* a runtime request instead of a static one.
* - 'force-disabled' disables prefetching for the segment.
*/
unstable_prefetch?: Prefetch
prefetch?: Prefetch
/**
* The stale time for dynamic responses in seconds.
......
......@@ -72,7 +72,7 @@ checkFields<Diff<{
config?: {}
generateStaticParams?: Function
unstable_instant?: InstantConfigForTypeCheckInternal
unstable_prefetch?: Prefetch
prefetch?: Prefetch
unstable_dynamicStaleTime?: number
revalidate?: RevalidateRange<TEntry> | false
dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static'
......
......@@ -237,7 +237,7 @@ async function createComponentTreeInternal(
: []
const prefetchConfig = layoutOrPageMod
? (layoutOrPageMod as AppSegmentConfig).unstable_prefetch
? (layoutOrPageMod as AppSegmentConfig).prefetch
: undefined
const hasRuntimePrefetch = prefetchConfig === 'allow-runtime'
const isRuntimePrefetchable = hasRuntimePrefetch || parentRuntimePrefetchable
......
......@@ -30,8 +30,8 @@ async function createFlightRouterStateFromLoaderTreeImpl(
{},
]
// Load the layout or page module to check for unstable_instant/unstable_prefetch
// config. When a segment doesn't export unstable_prefetch, it defaults to
// Load the layout or page module to check its unstable_instant and prefetch
// configs. When a segment doesn't export prefetch, it defaults to
// 'partial' if the app has opted into partial prefetching globally via the
// `partialPrefetching` config in next.config.js.
const mod = layout ? await layout[0]() : page ? await page[0]() : undefined
......@@ -39,7 +39,7 @@ async function createFlightRouterStateFromLoaderTreeImpl(
? (mod as AppSegmentConfig).unstable_instant
: undefined
const prefetchConfig =
(mod ? (mod as AppSegmentConfig).unstable_prefetch : undefined) ??
(mod ? (mod as AppSegmentConfig).prefetch : undefined) ??
(partialPrefetching === 'unstable_eager'
? 'unstable_eager'
: partialPrefetching
......
......@@ -57,7 +57,7 @@ export async function anySegmentHasRuntimePrefetchEnabled(
// TODO(restart-on-cache-miss): Does this work correctly for client page/layout modules?
const prefetchConfig = layoutOrPageMod
? (layoutOrPageMod as AppSegmentConfig).unstable_prefetch
? (layoutOrPageMod as AppSegmentConfig).prefetch
: undefined
if (prefetchConfig === 'allow-runtime') {
return true
......
......@@ -1187,13 +1187,12 @@ export async function createCombinedPayloadAtDepth(
: createChildSegmentPath(parentPath, key!, segment)
let instantConfig: Instant | null = null
let prefetchConfig: AppSegmentConfig['unstable_prefetch'] | null = null
let prefetchConfig: AppSegmentConfig['prefetch'] | null = null
let localCreateInstantStack: (() => Error) | null = null
if (layoutOrPageMod !== undefined) {
instantConfig =
(layoutOrPageMod as AppSegmentConfig).unstable_instant ?? null
prefetchConfig =
(layoutOrPageMod as AppSegmentConfig).unstable_prefetch ?? null
prefetchConfig = (layoutOrPageMod as AppSegmentConfig).prefetch ?? null
// When the default validation level is active and this is a page or
// default segment without an explicit config, treat it as if
......
......@@ -1770,8 +1770,8 @@ export interface NextConfig {
/**
* Opts the whole app into Partial Prefetching: `<Link prefetch={true}>`
* prefetches only the static parts of a route, never its dynamic data.
* When `true`, the default segment-level `unstable_prefetch` becomes
* `'partial'`; per-segment `unstable_prefetch` exports still win. Requires
* When `true`, the default segment-level `prefetch` becomes
* `'partial'`; per-segment `prefetch` exports still win. Requires
* `cacheComponents: true`.
*
* When `false` or omitted, this does nothing (the legacy behavior, where
......
......@@ -156,8 +156,8 @@ const API_DOCS: Record<
// `getSemanticDiagnosticsForExportVariableStatement` below, and only provide hover a tooltip + autocomplete.
insertText: 'unstable_instant = true;',
},
unstable_prefetch: {
description: `Controls prefetching behavior for this segment. This configuration is currently under development and will change.`,
prefetch: {
description: `Controls prefetching behavior for this segment. Some options are experimental and may change.`,
link: '(docs coming soon)',
type: `"auto" | "partial" | "unstable_eager" | "force-disabled" | "allow-runtime"`,
options: {
......@@ -172,7 +172,7 @@ const API_DOCS: Record<
'allow-runtime':
'Allows Next.js to prefetch this segment with a runtime server request so it can access session data, such as cookies.',
},
insertText: `unstable_prefetch = 'allow-runtime';`,
insertText: `prefetch = 'allow-runtime';`,
},
unstable_dynamicStaleTime: {
description: `Controls how long the client-side router cache retains dynamic page data (in seconds). Pages only — not allowed in layouts. Cannot be combined with \`unstable_instant\`.`,
......
......@@ -47,11 +47,11 @@ Set the instant cookie (per shared `instant cookie` section) any time after the
Apply the shared lever rules from SKILL.md; push-down recipes work at layouts too.
**Nav-only third lever: private cache + runtime prefetch.** For I/O that reads `cookies()` / `headers()` / `searchParams`, shared `'use cache'` won't help — those reads bail to dynamic. Use `'use cache: private'` + `cacheLife({ stale: N })` on **the scope that encloses the request-API read** (see scope rule below), plus `unstable_prefetch = 'allow-runtime'` as a route segment config (page or layout export) on the segment that owns the private content. Private-cache results live only in the browser — **never stored on the server** — so allowing runtime prefetching lets Next.js resolve them at link-visibility time with the user's session; the click commits with cookie-derived data already in place.
**Nav-only third lever: private cache + runtime prefetch.** For I/O that reads `cookies()` / `headers()` / `searchParams`, shared `'use cache'` won't help — those reads bail to dynamic. Use `'use cache: private'` + `cacheLife({ stale: N })` on **the scope that encloses the request-API read** (see scope rule below), plus `prefetch = 'allow-runtime'` as a route segment config (page or layout export) on the segment that owns the private content. Private-cache results live only in the browser — **never stored on the server** — so allowing runtime prefetching lets Next.js resolve them at link-visibility time with the user's session; the click commits with cookie-derived data already in place.
**Scope rule when cookie-read and data-fetch live in different frames.** The directive's semantics are about the cache scope enclosing the request-API call, not "the I/O function" as a label. If a page reads `cookies()` and passes the value into a separate fetch helper, putting `'use cache: private'` on the helper alone leaves the cookie read outside any cache scope and the segment stays dynamic. Either move the directive up to the frame that reads cookies, or move the cookie read down into the helper. Compiles and typechecks either way — only runtime behavior tells you which is correct.
The `unstable_prefetch` flag applies to the segment plus every descendant — put it on the most ancestral segment with runtime-cacheable content (layout-level covers all child pages; page-level covers only that page). Server Component only (not allowed with `"use client"`); requires `cacheComponents: true`. Valid values: `'auto'` (default) / `'force-disabled'` / `'force-static'` / `'allow-runtime'`. It doesn't make any segment cacheable on its own (each still needs `'use cache: private'`), doesn't help cold loads (no `<Link>` to prefetch from), and doesn't override `await connection()`.
The `prefetch` flag applies to the segment plus every descendant — put it on the most ancestral segment with runtime-cacheable content (layout-level covers all child pages; page-level covers only that page). Server Component only (not allowed with `"use client"`); requires `cacheComponents: true`. Valid values: `'auto'` (default) / `'force-disabled'` / `'force-static'` / `'allow-runtime'`. It doesn't make any segment cacheable on its own (each still needs `'use cache: private'`), doesn't help cold loads (no `<Link>` to prefetch from), and doesn't override `await connection()`.
### verify
......@@ -80,7 +80,7 @@ agent-browser pushstate <url> client-side navigation (no
'use cache: private' per-session cache; cookies /
headers / searchParams reads ok
unstable_prefetch = 'allow-runtime' route-level: permits runtime
prefetch = 'allow-runtime' route-level: permits runtime
prefetching of private-cached
content when <Link> is visible
......
......@@ -4,7 +4,7 @@ import { connection } from 'next/server'
import { Suspense } from 'react'
export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__PAGE__'
......
......@@ -3,7 +3,7 @@ import { UncachedFetch, CachedData } from '../data-fetching'
import { PrivateCachedData } from './data-fetching'
export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
const CACHE_KEY = '/private-cache/__LAYOUT__'
......
......@@ -3,7 +3,7 @@ import { UncachedFetch, CachedData } from '../data-fetching'
import { ShortLivedCache } from './data-fetching'
export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__LAYOUT__'
......
......@@ -2,7 +2,7 @@ import { Suspense } from 'react'
import { UncachedFetch, CachedFetch, CachedData } from '../data-fetching'
export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__LAYOUT__'
......
export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -3,7 +3,7 @@ import { CachedData, getCachedData } from '../../data-fetching'
import { cookies } from 'next/headers'
export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__PAGE__'
......
import { CachedData, getCachedData } from '../../data-fetching'
export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__PAGE__'
......
......@@ -2,7 +2,7 @@ import { Suspense } from 'react'
import { Static, Runtime, Dynamic } from '../shared'
export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Root({ children }: { children: React.ReactNode }) {
return (
......
import { Suspense } from 'react'
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
searchParams,
......
......@@ -4,7 +4,7 @@ import Link from 'next/link'
import { ClientFeatures } from './client'
import { HydrationMarker } from '../../hydration-marker'
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
function Box({
label,
......
......@@ -4,7 +4,7 @@ import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ searchParams: { myParam: 'testValue' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
type SearchParams = { [key: string]: string | string[] | undefined }
......
......@@ -9,7 +9,7 @@ export const unstable_instant: {
} = {
unstable_samples: [{ params: { slug: 'anything' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function UngeneratedParamsRuntimePage({
params,
......
......@@ -3,7 +3,7 @@ import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -3,7 +3,7 @@ import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -3,7 +3,7 @@ import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -15,7 +15,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -10,7 +10,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -10,7 +10,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -16,7 +16,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export function generateStaticParams() {
return [{ slug: 'foo' }, { slug: 'bar' }]
......
......@@ -6,7 +6,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ headers: [] }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -6,7 +6,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ headers: [] }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -6,7 +6,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ headers: [] }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -15,7 +15,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -10,7 +10,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -10,7 +10,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -5,7 +5,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ cookies: [{ name: 'auth', value: '1' }] }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
const c = await cookies()
......
......@@ -13,7 +13,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
params,
......
......@@ -13,7 +13,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
params,
......
......@@ -12,7 +12,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
params,
......
......@@ -5,7 +5,7 @@ export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [{ params: { slug: 'hello' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
params,
......
......@@ -5,7 +5,7 @@ export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [{ params: { slug: 'hello' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
params,
......
......@@ -4,7 +4,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ searchParams: { q: 'test' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
searchParams,
......
......@@ -4,7 +4,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ searchParams: { q: 'test' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
searchParams,
......
......@@ -12,7 +12,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Page() {
return (
......
......@@ -11,7 +11,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Page() {
return (
......
......@@ -16,7 +16,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
type SearchParams = Record<string, string | string[]>
......
......@@ -12,7 +12,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
searchParams,
......
......@@ -14,7 +14,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
searchParams,
......
......@@ -14,7 +14,7 @@ export const unstable_instant: Instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Page() {
return (
......
......@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { IgnoreServerContent } from './client'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Page() {
return (
......
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Page() {
return (
......
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Page() {
return (
......
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
await cachedIO('static')
......
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
await privateCachedIO()
......
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
await cookies()
......
......@@ -6,7 +6,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ cookies: [{ name: 'auth', value: '1' }] }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -8,7 +8,7 @@ export const unstable_instant: Instant = {
// no samples
unstable_samples: [{}],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
// Guard behind cookies() so that the rest of this component only runs during validation
......
......@@ -8,7 +8,7 @@ export const unstable_instant: Instant = {
// no samples
unstable_samples: [{}],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
// Guard behind cookies() so that the rest of this component only runs during validation
......
......@@ -7,7 +7,7 @@ export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [{ params: { lang: 'en-from-samples' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
// Guard behind cookies() so that the rest of this component only runs during validation
......
......@@ -2,7 +2,7 @@ export const unstable_instant = {
unstable_samples: [{ cookies: [] }],
unstable_disableValidation: true,
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Layout({ children }) {
return <>{children}</>
......
......@@ -4,7 +4,7 @@ export const unstable_instant = {
unstable_samples: [{ cookies: [] }],
unstable_disableValidation: true,
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
await connection()
......
......@@ -4,7 +4,7 @@ export const unstable_instant = {
unstable_samples: [{ cookies: [] }],
unstable_disableValidation: true,
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
await connection()
......
......@@ -4,7 +4,7 @@ import { connection } from 'next/server'
import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
// Note that we're inside a root layout with suspense, so we skip the static shell
export async function generateViewport(): Promise<Viewport> {
......
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Layout({ children }) {
return <>{children}</>
......
......@@ -4,7 +4,7 @@ import { connection } from 'next/server'
import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export async function generateMetadata(): Promise<Metadata> {
await connection()
......
......@@ -2,7 +2,7 @@ import type { Viewport } from 'next'
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export async function generateViewport(): Promise<Viewport> {
await cookies()
......
......@@ -2,7 +2,7 @@ import { Suspense } from 'react'
import { connection } from 'next/server'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function SlotPage() {
return (
......
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function RuntimeLayout({ children }) {
await cookies()
......
// Avoid static shell validation -- we only want to test the validation of `prefetch: 'runtime'` here.
export const unstable_instant = false
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function DisableStaticShell({ children }) {
return <>{children}</>
......
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
// This page HAS runtime prefetch enabled. cookies() is passed as a promise
// input to a public "use cache" function. The cache doesn't read the cookies
......
......@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export async function generateMetadata() {
await cookies()
......
......@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
async function Runtime() {
await cookies()
......
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
// This page HAS runtime prefetch enabled. The sync IO (Date.now()) after
// cookies() is invalid here because during a runtime prefetch, cookies()
......
import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
await cookies()
......
......@@ -2,7 +2,7 @@ import { connection } from 'next/server'
import { ReactNode } from 'react'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Layout({ children }: { children: ReactNode }) {
await connection()
......
......@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { connection } from 'next/server'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
await cookies()
......
......@@ -4,7 +4,7 @@ import { ReactNode } from 'react'
// runtime prefetching to handle dynamic data, but the parent layout
// above this one gets static prefetching by default and blocks.
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function InnerLayout({ children }: { children: ReactNode }) {
return (
......
......@@ -3,7 +3,7 @@ import { connection } from 'next/server'
import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { connection } from 'next/server'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
await cookies()
......
......@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function RuntimeLayout({ children }) {
await cookies()
......
......@@ -5,7 +5,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ cookies: [], params: { param: '123' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
params,
......
......@@ -5,7 +5,7 @@ export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ cookies: [], searchParams: { foo: 'bar' } }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
searchParams,
......
......@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
async function Runtime() {
await cookies()
......
......@@ -5,7 +5,7 @@ import { connection } from 'next/server'
// `SubtreeHasPartialPrefetching` hint originates here and must propagate up
// through the /a/b and /a layouts to the root for the scheduler to downgrade a
// `prefetch={true}` link into a partial (PPR) prefetch.
export const unstable_prefetch = 'partial'
export const prefetch = 'partial'
export default function Page() {
return (
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
// Note: Partial Prefetching is NOT enabled globally. The target route opts
// in per-segment via `unstable_prefetch = 'partial'` on a deeply nested page.
// in per-segment via `prefetch = 'partial'` on a deeply nested page.
cacheComponents: true,
}
......
......@@ -18,7 +18,7 @@ describe('partial prefetching - deep subtree-hint propagation', () => {
// even if the implementation details change.
//
// The route `/a/b/c` opts into Partial Prefetching on its leaf page via
// `export const unstable_prefetch = 'partial'`. The
// `export const prefetch = 'partial'`. The
// `SubtreeHasPartialPrefetching` hint originates on that leaf and must
// propagate up through the `/a/b` and `/a` layout segments to the ROOT of
// the route tree, because the prefetch scheduler reads the hint at the root
......
......@@ -4,7 +4,7 @@ import { connection } from 'next/server'
// Opts this route into partial prefetching at the segment level, without the
// global `partialPrefetching` flag. A `prefetch={true}` link should prefetch
// the static shell but never the dynamic data.
export const unstable_prefetch = 'partial'
export const prefetch = 'partial'
export default function Page() {
return (
......
......@@ -38,7 +38,7 @@ describe('partial prefetching segment config', () => {
)
})
it('does not prefetch dynamic data for a route with unstable_prefetch = "partial"', async () => {
it('does not prefetch dynamic data for a route with prefetch = "partial"', async () => {
let page: Playwright.Page
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
......@@ -49,7 +49,7 @@ describe('partial prefetching segment config', () => {
// Reveal the link to trigger its prefetch. The Link has prefetch={true},
// and the target route opts into partial prefetching via
// `export const unstable_prefetch = 'partial'`. So the prefetch should
// `export const prefetch = 'partial'`. So the prefetch should
// include the static shell, but NOT the dynamic data — even though the
// global config does not enable partial prefetching.
await act(async () => {
......
......@@ -3,7 +3,7 @@ import { ReactNode } from 'react'
export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'test', value: null }] }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default function Layout({ children }: { children: ReactNode }) {
return <div>{children}</div>
......
......@@ -5,7 +5,7 @@ import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'test', value: null }] }],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page() {
return (
......
......@@ -12,7 +12,7 @@ export const unstable_instant = {
},
],
}
export const unstable_prefetch = 'allow-runtime'
export const prefetch = 'allow-runtime'
export default async function Page({
searchParams,
......
......@@ -2,7 +2,7 @@ import { Suspense } from 'react'
type Params = { id: string }
// No per-segment `unstable_prefetch`. The route's prefetch config comes from
// No per-segment `prefetch`. The route's prefetch config comes from
// the global `partialPrefetching: 'unstable_eager'` in next.config, which makes
// it eager — so the App Shells skip does NOT apply.
export function generateStaticParams() {
......
......@@ -5,7 +5,7 @@ const nextConfig: NextConfig = {
// Opt the whole app into Partial Prefetching in "eager" mode. Every route's
// default prefetch config becomes 'unstable_eager', so under App Shells the
// per-link Speculative prefetch is NOT skipped — even for routes with no
// per-segment `unstable_prefetch` export.
// per-segment `prefetch` export.
partialPrefetching: 'unstable_eager',
experimental: {
prefetchInlining: true,
......
......@@ -3,12 +3,12 @@ import { Suspense } from 'react'
type Params = { id: string }
// Combines both segment-level opt-ins: `unstable_instant` (which on its own
// behaves like 'partial' — not eager) AND `unstable_prefetch = 'unstable_eager'`.
// behaves like 'partial' — not eager) AND `prefetch = 'unstable_eager'`.
// 'unstable_eager' wins: the segment is marked eager, so under App Shells the
// per-link Speculative prefetch still fires and the param-specific content
// below IS prefetched.
export const unstable_instant = true
export const unstable_prefetch = 'unstable_eager'
export const prefetch = 'unstable_eager'
export function generateStaticParams() {
return [{ id: '1' }, { id: '2' }, { id: '3' }]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment