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 { ...@@ -124,7 +124,7 @@ pub struct NextSegmentConfig {
pub unstable_instant: Option<Span>, pub unstable_instant: Option<Span>,
#[turbo_tasks(trace_ignore)] #[turbo_tasks(trace_ignore)]
#[bincode(with_serde)] #[bincode(with_serde)]
pub unstable_prefetch: Option<Span>, pub prefetch: Option<Span>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -565,15 +565,15 @@ pub async fn parse_segment_config_from_source( ...@@ -565,15 +565,15 @@ pub async fn parse_segment_config_from_source(
.await?; .await?;
} }
if let Some(span) = config.unstable_prefetch { if let Some(span) = config.prefetch {
invalid_config( invalid_config(
source, source,
"unstable_prefetch", "prefetch",
span, span,
rcstr!( rcstr!(
"\"unstable_prefetch\" is a route segment config and can only be used when \ "\"prefetch\" is a route segment config and can only be used when the segment \
the segment is a Server Component module. Remove the \"use client\" \ is a Server Component module. Remove the \"use client\" directive to use \
directive to use this API." this API."
), ),
None, None,
IssueSeverity::Error, IssueSeverity::Error,
...@@ -1004,8 +1004,8 @@ async fn parse_config_value( ...@@ -1004,8 +1004,8 @@ async fn parse_config_value(
"unstable_instant" => { "unstable_instant" => {
config.unstable_instant = Some(span); config.unstable_instant = Some(span);
} }
"unstable_prefetch" => { "prefetch" => {
config.unstable_prefetch = Some(span); config.prefetch = Some(span);
} }
_ => {} _ => {}
} }
......
...@@ -10,17 +10,17 @@ related: ...@@ -10,17 +10,17 @@ related:
- app/api-reference/file-conventions/route-segment-config/instant - 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. 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**: > **Good to know**:
> >
> - The `unstable_prefetch` export only works when [`cacheComponents`](/docs/app/api-reference/config/next-config-js/cacheComponents) is enabled. > - The `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. > - `prefetch` cannot be used when the segment is a Client Component.
```tsx filename="layout.tsx | page.tsx" switcher ```tsx filename="layout.tsx | page.tsx" switcher
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Page() { export default function Page() {
return <div>...</div> return <div>...</div>
...@@ -28,7 +28,7 @@ export default function Page() { ...@@ -28,7 +28,7 @@ export default function Page() {
``` ```
```jsx filename="layout.js | page.js" switcher ```jsx filename="layout.js | page.js" switcher
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Page() { export default function Page() {
return <div>...</div> return <div>...</div>
...@@ -52,7 +52,7 @@ Allows Next.js to prefetch this segment at runtime. Today, setting this option c ...@@ -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. > **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" ```tsx filename="page.tsx"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
``` ```
### `'force-static'` ### `'force-static'`
...@@ -67,7 +67,7 @@ Never prefetch this segment. The client will not request segment data ahead of n ...@@ -67,7 +67,7 @@ Never prefetch this segment. The client will not request segment data ahead of n
## Relationship with the `<Link prefetch>` prop ## 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 **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. - 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 ...@@ -79,11 +79,11 @@ In general, both of these are special circumstances. The default behavior — wh
```tsx ```tsx
type Prefetch = 'auto' | 'force-disabled' | 'force-static' | 'allow-runtime' 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 History
| Version | Changes | | Version | Changes |
| --------- | ------------------------------------------------------------- | | --------- | ---------------------------------------------------- |
| `v16.x.x` | `unstable_prefetch` export introduced (Cache Components only) | | `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 ...@@ -19,7 +19,7 @@ If you are generating a token to talk to a database that itself should be cached
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
async function getCachedData(token: string, userId: string) { async function getCachedData(token: string, userId: string) {
"use cache" "use cache"
...@@ -37,7 +37,7 @@ export default async function Page({ params }) { ...@@ -37,7 +37,7 @@ export default async function Page({ params }) {
After: After:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
async function getCachedData(userId: string) { async function getCachedData(userId: string) {
"use cache" "use cache"
...@@ -59,7 +59,7 @@ If you require this random value to be unique per Request and an async version o ...@@ -59,7 +59,7 @@ If you require this random value to be unique per Request and an async version o
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
import { generateKeySync } from 'node:crypto' import { generateKeySync } from 'node:crypto'
...@@ -75,7 +75,7 @@ export default async function Page({ params }) { ...@@ -75,7 +75,7 @@ export default async function Page({ params }) {
After: After:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
import { generateKey } from 'node:crypto' 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 ...@@ -95,7 +95,7 @@ If you require this random value to be unique per Request and an async version o
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ params }) { export default async function Page({ params }) {
const { sessionId } = await params const { sessionId } = await params
...@@ -107,7 +107,7 @@ export default async function Page({ params }) { ...@@ -107,7 +107,7 @@ export default async function Page({ params }) {
After: After:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
import { connection } from 'next/server' import { connection } from 'next/server'
......
...@@ -23,7 +23,7 @@ If you are using the current time for performance tracking with elapsed time use ...@@ -23,7 +23,7 @@ If you are using the current time for performance tracking with elapsed time use
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ params }) { export default async function Page({ params }) {
const { id } = await params const { id } = await params
...@@ -39,7 +39,7 @@ export default async function Page({ params }) { ...@@ -39,7 +39,7 @@ export default async function Page({ params }) {
After: After:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ params }) { export default async function Page({ params }) {
const { id } = await 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 ...@@ -61,7 +61,7 @@ If you want to read the time when some cache entry is created (such as when a Ne
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
async function InformationTable({ id }) { async function InformationTable({ id }) {
const data = await fetch(urlFrom(id)) const data = await fetch(urlFrom(id))
...@@ -87,7 +87,7 @@ export default async function Page({ params }) { ...@@ -87,7 +87,7 @@ export default async function Page({ params }) {
After: After:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
async function InformationTable({ id }) { async function InformationTable({ id }) {
'use cache' 'use cache'
...@@ -124,7 +124,7 @@ If you go with this approach you will need to ensure the Client Component which ...@@ -124,7 +124,7 @@ If you go with this approach you will need to ensure the Client Component which
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
function RelativeTime({ when }) { function RelativeTime({ when }) {
return computeTimeAgo(new Date(), when) return computeTimeAgo(new Date(), when)
...@@ -178,7 +178,7 @@ export function RelativeTime({ when }) { ...@@ -178,7 +178,7 @@ export function RelativeTime({ when }) {
``` ```
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
import { RelativeTime } from './relative-time' import { RelativeTime } from './relative-time'
...@@ -212,7 +212,7 @@ Next.js enforces that it can always produce at least a partially static initial ...@@ -212,7 +212,7 @@ Next.js enforces that it can always produce at least a partially static initial
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
const lastImpressionTime = (await cookies()).get( const lastImpressionTime = (await cookies()).get(
...@@ -230,7 +230,7 @@ export default async function Page() { ...@@ -230,7 +230,7 @@ export default async function Page() {
After: After:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
import { Suspense } from 'react' import { Suspense } from 'react'
import { connection } from 'next/server' import { connection } from 'next/server'
......
...@@ -23,7 +23,7 @@ If your random value is cacheable, move the `Math.random()` call to a `"use cach ...@@ -23,7 +23,7 @@ If your random value is cacheable, move the `Math.random()` call to a `"use cach
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ params }) { export default async function Page({ params }) {
const { category } = await params const { category } = await params
...@@ -37,7 +37,7 @@ export default async function Page({ params }) { ...@@ -37,7 +37,7 @@ export default async function Page({ params }) {
After: After:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
async function RandomizedProductsView({ category }) { async function RandomizedProductsView({ category }) {
'use cache' 'use cache'
...@@ -62,7 +62,7 @@ If you want the random value to be evaluated on each Request precede it with `aw ...@@ -62,7 +62,7 @@ If you want the random value to be evaluated on each Request precede it with `aw
Before: Before:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ params }) { export default async function Page({ params }) {
const { category } = await params const { category } = await params
...@@ -76,7 +76,7 @@ export default async function Page({ params }) { ...@@ -76,7 +76,7 @@ export default async function Page({ params }) {
After: After:
```jsx filename="app/page.js" ```jsx filename="app/page.js"
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
import { connection } from 'next/server' import { connection } from 'next/server'
......
...@@ -1303,5 +1303,7 @@ ...@@ -1303,5 +1303,7 @@
"1302": "Attempted to advance to stage %s but the render is limited to %s", "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", "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", "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({ ...@@ -712,16 +712,16 @@ export async function getAppPageStaticInfo({
) )
} }
// Prevent use client and unstable_prefetch in the same file. // Prevent use client and prefetch in the same file.
if (directives?.has('client') && 'unstable_prefetch' in config) { if (directives?.has('client') && 'prefetch' in config) {
throw new Error( 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( 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({ ...@@ -150,7 +150,7 @@ const AppSegmentConfigSchema = z.object({
* a runtime request instead of a static one. * a runtime request instead of a static one.
* - 'force-disabled' disables prefetching for the segment. * - 'force-disabled' disables prefetching for the segment.
*/ */
unstable_prefetch: PrefetchSchema.optional(), prefetch: PrefetchSchema.optional(),
/** /**
* The stale time for dynamic responses in seconds. * The stale time for dynamic responses in seconds.
...@@ -202,9 +202,9 @@ export function parseAppSegmentConfig( ...@@ -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`, 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 { 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': { case 'unstable_dynamicStaleTime': {
...@@ -278,7 +278,7 @@ export type AppSegmentConfig = { ...@@ -278,7 +278,7 @@ export type AppSegmentConfig = {
* a runtime request instead of a static one. * a runtime request instead of a static one.
* - 'force-disabled' disables prefetching for the segment. * - 'force-disabled' disables prefetching for the segment.
*/ */
unstable_prefetch?: Prefetch prefetch?: Prefetch
/** /**
* The stale time for dynamic responses in seconds. * The stale time for dynamic responses in seconds.
......
...@@ -72,7 +72,7 @@ checkFields<Diff<{ ...@@ -72,7 +72,7 @@ checkFields<Diff<{
config?: {} config?: {}
generateStaticParams?: Function generateStaticParams?: Function
unstable_instant?: InstantConfigForTypeCheckInternal unstable_instant?: InstantConfigForTypeCheckInternal
unstable_prefetch?: Prefetch prefetch?: Prefetch
unstable_dynamicStaleTime?: number unstable_dynamicStaleTime?: number
revalidate?: RevalidateRange<TEntry> | false revalidate?: RevalidateRange<TEntry> | false
dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static' dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static'
......
...@@ -237,7 +237,7 @@ async function createComponentTreeInternal( ...@@ -237,7 +237,7 @@ async function createComponentTreeInternal(
: [] : []
const prefetchConfig = layoutOrPageMod const prefetchConfig = layoutOrPageMod
? (layoutOrPageMod as AppSegmentConfig).unstable_prefetch ? (layoutOrPageMod as AppSegmentConfig).prefetch
: undefined : undefined
const hasRuntimePrefetch = prefetchConfig === 'allow-runtime' const hasRuntimePrefetch = prefetchConfig === 'allow-runtime'
const isRuntimePrefetchable = hasRuntimePrefetch || parentRuntimePrefetchable const isRuntimePrefetchable = hasRuntimePrefetch || parentRuntimePrefetchable
......
...@@ -30,8 +30,8 @@ async function createFlightRouterStateFromLoaderTreeImpl( ...@@ -30,8 +30,8 @@ async function createFlightRouterStateFromLoaderTreeImpl(
{}, {},
] ]
// Load the layout or page module to check for unstable_instant/unstable_prefetch // Load the layout or page module to check its unstable_instant and prefetch
// config. When a segment doesn't export unstable_prefetch, it defaults to // configs. When a segment doesn't export prefetch, it defaults to
// 'partial' if the app has opted into partial prefetching globally via the // 'partial' if the app has opted into partial prefetching globally via the
// `partialPrefetching` config in next.config.js. // `partialPrefetching` config in next.config.js.
const mod = layout ? await layout[0]() : page ? await page[0]() : undefined const mod = layout ? await layout[0]() : page ? await page[0]() : undefined
...@@ -39,7 +39,7 @@ async function createFlightRouterStateFromLoaderTreeImpl( ...@@ -39,7 +39,7 @@ async function createFlightRouterStateFromLoaderTreeImpl(
? (mod as AppSegmentConfig).unstable_instant ? (mod as AppSegmentConfig).unstable_instant
: undefined : undefined
const prefetchConfig = const prefetchConfig =
(mod ? (mod as AppSegmentConfig).unstable_prefetch : undefined) ?? (mod ? (mod as AppSegmentConfig).prefetch : undefined) ??
(partialPrefetching === 'unstable_eager' (partialPrefetching === 'unstable_eager'
? 'unstable_eager' ? 'unstable_eager'
: partialPrefetching : partialPrefetching
......
...@@ -57,7 +57,7 @@ export async function anySegmentHasRuntimePrefetchEnabled( ...@@ -57,7 +57,7 @@ export async function anySegmentHasRuntimePrefetchEnabled(
// TODO(restart-on-cache-miss): Does this work correctly for client page/layout modules? // TODO(restart-on-cache-miss): Does this work correctly for client page/layout modules?
const prefetchConfig = layoutOrPageMod const prefetchConfig = layoutOrPageMod
? (layoutOrPageMod as AppSegmentConfig).unstable_prefetch ? (layoutOrPageMod as AppSegmentConfig).prefetch
: undefined : undefined
if (prefetchConfig === 'allow-runtime') { if (prefetchConfig === 'allow-runtime') {
return true return true
......
...@@ -1187,13 +1187,12 @@ export async function createCombinedPayloadAtDepth( ...@@ -1187,13 +1187,12 @@ export async function createCombinedPayloadAtDepth(
: createChildSegmentPath(parentPath, key!, segment) : createChildSegmentPath(parentPath, key!, segment)
let instantConfig: Instant | null = null let instantConfig: Instant | null = null
let prefetchConfig: AppSegmentConfig['unstable_prefetch'] | null = null let prefetchConfig: AppSegmentConfig['prefetch'] | null = null
let localCreateInstantStack: (() => Error) | null = null let localCreateInstantStack: (() => Error) | null = null
if (layoutOrPageMod !== undefined) { if (layoutOrPageMod !== undefined) {
instantConfig = instantConfig =
(layoutOrPageMod as AppSegmentConfig).unstable_instant ?? null (layoutOrPageMod as AppSegmentConfig).unstable_instant ?? null
prefetchConfig = prefetchConfig = (layoutOrPageMod as AppSegmentConfig).prefetch ?? null
(layoutOrPageMod as AppSegmentConfig).unstable_prefetch ?? null
// When the default validation level is active and this is a page or // When the default validation level is active and this is a page or
// default segment without an explicit config, treat it as if // default segment without an explicit config, treat it as if
......
...@@ -1770,8 +1770,8 @@ export interface NextConfig { ...@@ -1770,8 +1770,8 @@ export interface NextConfig {
/** /**
* Opts the whole app into Partial Prefetching: `<Link prefetch={true}>` * Opts the whole app into Partial Prefetching: `<Link prefetch={true}>`
* prefetches only the static parts of a route, never its dynamic data. * prefetches only the static parts of a route, never its dynamic data.
* When `true`, the default segment-level `unstable_prefetch` becomes * When `true`, the default segment-level `prefetch` becomes
* `'partial'`; per-segment `unstable_prefetch` exports still win. Requires * `'partial'`; per-segment `prefetch` exports still win. Requires
* `cacheComponents: true`. * `cacheComponents: true`.
* *
* When `false` or omitted, this does nothing (the legacy behavior, where * When `false` or omitted, this does nothing (the legacy behavior, where
......
...@@ -156,8 +156,8 @@ const API_DOCS: Record< ...@@ -156,8 +156,8 @@ const API_DOCS: Record<
// `getSemanticDiagnosticsForExportVariableStatement` below, and only provide hover a tooltip + autocomplete. // `getSemanticDiagnosticsForExportVariableStatement` below, and only provide hover a tooltip + autocomplete.
insertText: 'unstable_instant = true;', insertText: 'unstable_instant = true;',
}, },
unstable_prefetch: { prefetch: {
description: `Controls prefetching behavior for this segment. This configuration is currently under development and will change.`, description: `Controls prefetching behavior for this segment. Some options are experimental and may change.`,
link: '(docs coming soon)', link: '(docs coming soon)',
type: `"auto" | "partial" | "unstable_eager" | "force-disabled" | "allow-runtime"`, type: `"auto" | "partial" | "unstable_eager" | "force-disabled" | "allow-runtime"`,
options: { options: {
...@@ -172,7 +172,7 @@ const API_DOCS: Record< ...@@ -172,7 +172,7 @@ const API_DOCS: Record<
'allow-runtime': 'allow-runtime':
'Allows Next.js to prefetch this segment with a runtime server request so it can access session data, such as cookies.', '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: { 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\`.`, 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 ...@@ -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. 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. **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 ### verify
...@@ -80,7 +80,7 @@ agent-browser pushstate <url> client-side navigation (no ...@@ -80,7 +80,7 @@ agent-browser pushstate <url> client-side navigation (no
'use cache: private' per-session cache; cookies / 'use cache: private' per-session cache; cookies /
headers / searchParams reads ok headers / searchParams reads ok
unstable_prefetch = 'allow-runtime' route-level: permits runtime prefetch = 'allow-runtime' route-level: permits runtime
prefetching of private-cached prefetching of private-cached
content when <Link> is visible content when <Link> is visible
......
...@@ -4,7 +4,7 @@ import { connection } from 'next/server' ...@@ -4,7 +4,7 @@ import { connection } from 'next/server'
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__PAGE__' const CACHE_KEY = __dirname + '/__PAGE__'
......
...@@ -3,7 +3,7 @@ import { UncachedFetch, CachedData } from '../data-fetching' ...@@ -3,7 +3,7 @@ import { UncachedFetch, CachedData } from '../data-fetching'
import { PrivateCachedData } from './data-fetching' import { PrivateCachedData } from './data-fetching'
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
const CACHE_KEY = '/private-cache/__LAYOUT__' const CACHE_KEY = '/private-cache/__LAYOUT__'
......
...@@ -3,7 +3,7 @@ import { UncachedFetch, CachedData } from '../data-fetching' ...@@ -3,7 +3,7 @@ import { UncachedFetch, CachedData } from '../data-fetching'
import { ShortLivedCache } from './data-fetching' import { ShortLivedCache } from './data-fetching'
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__LAYOUT__' const CACHE_KEY = __dirname + '/__LAYOUT__'
......
...@@ -2,7 +2,7 @@ import { Suspense } from 'react' ...@@ -2,7 +2,7 @@ import { Suspense } from 'react'
import { UncachedFetch, CachedFetch, CachedData } from '../data-fetching' import { UncachedFetch, CachedFetch, CachedData } from '../data-fetching'
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__LAYOUT__' const CACHE_KEY = __dirname + '/__LAYOUT__'
......
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -3,7 +3,7 @@ import { CachedData, getCachedData } from '../../data-fetching' ...@@ -3,7 +3,7 @@ import { CachedData, getCachedData } from '../../data-fetching'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__PAGE__' const CACHE_KEY = __dirname + '/__PAGE__'
......
import { CachedData, getCachedData } from '../../data-fetching' import { CachedData, getCachedData } from '../../data-fetching'
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
const CACHE_KEY = __dirname + '/__PAGE__' const CACHE_KEY = __dirname + '/__PAGE__'
......
...@@ -2,7 +2,7 @@ import { Suspense } from 'react' ...@@ -2,7 +2,7 @@ import { Suspense } from 'react'
import { Static, Runtime, Dynamic } from '../shared' import { Static, Runtime, Dynamic } from '../shared'
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Root({ children }: { children: React.ReactNode }) { export default function Root({ children }: { children: React.ReactNode }) {
return ( return (
......
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ export default async function Page({
searchParams, searchParams,
......
...@@ -4,7 +4,7 @@ import Link from 'next/link' ...@@ -4,7 +4,7 @@ import Link from 'next/link'
import { ClientFeatures } from './client' import { ClientFeatures } from './client'
import { HydrationMarker } from '../../hydration-marker' import { HydrationMarker } from '../../hydration-marker'
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
function Box({ function Box({
label, label,
......
...@@ -4,7 +4,7 @@ import { connection } from 'next/server' ...@@ -4,7 +4,7 @@ import { connection } from 'next/server'
export const unstable_instant = { export const unstable_instant = {
unstable_samples: [{ searchParams: { myParam: 'testValue' } }], unstable_samples: [{ searchParams: { myParam: 'testValue' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
type SearchParams = { [key: string]: string | string[] | undefined } type SearchParams = { [key: string]: string | string[] | undefined }
......
...@@ -9,7 +9,7 @@ export const unstable_instant: { ...@@ -9,7 +9,7 @@ export const unstable_instant: {
} = { } = {
unstable_samples: [{ params: { slug: 'anything' } }], unstable_samples: [{ params: { slug: 'anything' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function UngeneratedParamsRuntimePage({ export default function UngeneratedParamsRuntimePage({
params, params,
......
...@@ -3,7 +3,7 @@ import { Suspense } from 'react' ...@@ -3,7 +3,7 @@ import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error' import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -3,7 +3,7 @@ import { Suspense } from 'react' ...@@ -3,7 +3,7 @@ import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error' import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -3,7 +3,7 @@ import { Suspense } from 'react' ...@@ -3,7 +3,7 @@ import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error' import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -15,7 +15,7 @@ export const unstable_instant: Instant = { ...@@ -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() { export default async function Page() {
return ( return (
......
...@@ -10,7 +10,7 @@ export const unstable_instant: Instant = { ...@@ -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() { export default async function Page() {
return ( return (
......
...@@ -10,7 +10,7 @@ export const unstable_instant: Instant = { ...@@ -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() { export default async function Page() {
return ( return (
......
...@@ -16,7 +16,7 @@ export const unstable_instant: Instant = { ...@@ -16,7 +16,7 @@ export const unstable_instant: Instant = {
}, },
], ],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export function generateStaticParams() { export function generateStaticParams() {
return [{ slug: 'foo' }, { slug: 'bar' }] return [{ slug: 'foo' }, { slug: 'bar' }]
......
...@@ -6,7 +6,7 @@ export const unstable_instant = { ...@@ -6,7 +6,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ headers: [] }], unstable_samples: [{ headers: [] }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -6,7 +6,7 @@ export const unstable_instant = { ...@@ -6,7 +6,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ headers: [] }], unstable_samples: [{ headers: [] }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -6,7 +6,7 @@ export const unstable_instant = { ...@@ -6,7 +6,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ headers: [] }], unstable_samples: [{ headers: [] }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -15,7 +15,7 @@ export const unstable_instant: Instant = { ...@@ -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() { export default async function Page() {
return ( return (
......
...@@ -10,7 +10,7 @@ export const unstable_instant: Instant = { ...@@ -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() { export default async function Page() {
return ( return (
......
...@@ -10,7 +10,7 @@ export const unstable_instant: Instant = { ...@@ -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() { export default async function Page() {
return ( return (
......
...@@ -5,7 +5,7 @@ export const unstable_instant = { ...@@ -5,7 +5,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ cookies: [{ name: 'auth', value: '1' }] }], unstable_samples: [{ cookies: [{ name: 'auth', value: '1' }] }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
const c = await cookies() const c = await cookies()
......
...@@ -13,7 +13,7 @@ export const unstable_instant: Instant = { ...@@ -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({ export default async function Page({
params, params,
......
...@@ -13,7 +13,7 @@ export const unstable_instant: Instant = { ...@@ -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({ export default async function Page({
params, params,
......
...@@ -12,7 +12,7 @@ export const unstable_instant: Instant = { ...@@ -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({ export default async function Page({
params, params,
......
...@@ -5,7 +5,7 @@ export const unstable_instant: Instant = { ...@@ -5,7 +5,7 @@ export const unstable_instant: Instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ params: { slug: 'hello' } }], unstable_samples: [{ params: { slug: 'hello' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ export default async function Page({
params, params,
......
...@@ -5,7 +5,7 @@ export const unstable_instant: Instant = { ...@@ -5,7 +5,7 @@ export const unstable_instant: Instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ params: { slug: 'hello' } }], unstable_samples: [{ params: { slug: 'hello' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ export default async function Page({
params, params,
......
...@@ -4,7 +4,7 @@ export const unstable_instant = { ...@@ -4,7 +4,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ searchParams: { q: 'test' } }], unstable_samples: [{ searchParams: { q: 'test' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ export default async function Page({
searchParams, searchParams,
......
...@@ -4,7 +4,7 @@ export const unstable_instant = { ...@@ -4,7 +4,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ searchParams: { q: 'test' } }], unstable_samples: [{ searchParams: { q: 'test' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ export default async function Page({
searchParams, searchParams,
......
...@@ -12,7 +12,7 @@ export const unstable_instant: Instant = { ...@@ -12,7 +12,7 @@ export const unstable_instant: Instant = {
}, },
], ],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Page() { export default function Page() {
return ( return (
......
...@@ -11,7 +11,7 @@ export const unstable_instant: Instant = { ...@@ -11,7 +11,7 @@ export const unstable_instant: Instant = {
}, },
], ],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Page() { export default function Page() {
return ( return (
......
...@@ -16,7 +16,7 @@ export const unstable_instant: Instant = { ...@@ -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[]> type SearchParams = Record<string, string | string[]>
......
...@@ -12,7 +12,7 @@ export const unstable_instant: Instant = { ...@@ -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({ export default async function Page({
searchParams, searchParams,
......
...@@ -14,7 +14,7 @@ export const unstable_instant: Instant = { ...@@ -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({ export default async function Page({
searchParams, searchParams,
......
...@@ -14,7 +14,7 @@ export const unstable_instant: Instant = { ...@@ -14,7 +14,7 @@ export const unstable_instant: Instant = {
}, },
], ],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Page() { export default function Page() {
return ( return (
......
...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers' ...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { IgnoreServerContent } from './client' import { IgnoreServerContent } from './client'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Page() { export default function Page() {
return ( return (
......
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Page() { export default function Page() {
return ( return (
......
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Page() { export default function Page() {
return ( return (
......
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
await cachedIO('static') await cachedIO('static')
......
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
await privateCachedIO() await privateCachedIO()
......
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
await cookies() await cookies()
......
...@@ -6,7 +6,7 @@ export const unstable_instant = { ...@@ -6,7 +6,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ cookies: [{ name: 'auth', value: '1' }] }], unstable_samples: [{ cookies: [{ name: 'auth', value: '1' }] }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -8,7 +8,7 @@ export const unstable_instant: Instant = { ...@@ -8,7 +8,7 @@ export const unstable_instant: Instant = {
// no samples // no samples
unstable_samples: [{}], unstable_samples: [{}],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
// Guard behind cookies() so that the rest of this component only runs during validation // Guard behind cookies() so that the rest of this component only runs during validation
......
...@@ -8,7 +8,7 @@ export const unstable_instant: Instant = { ...@@ -8,7 +8,7 @@ export const unstable_instant: Instant = {
// no samples // no samples
unstable_samples: [{}], unstable_samples: [{}],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
// Guard behind cookies() so that the rest of this component only runs during validation // Guard behind cookies() so that the rest of this component only runs during validation
......
...@@ -7,7 +7,7 @@ export const unstable_instant: Instant = { ...@@ -7,7 +7,7 @@ export const unstable_instant: Instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ params: { lang: 'en-from-samples' } }], unstable_samples: [{ params: { lang: 'en-from-samples' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
// Guard behind cookies() so that the rest of this component only runs during validation // Guard behind cookies() so that the rest of this component only runs during validation
......
...@@ -2,7 +2,7 @@ export const unstable_instant = { ...@@ -2,7 +2,7 @@ export const unstable_instant = {
unstable_samples: [{ cookies: [] }], unstable_samples: [{ cookies: [] }],
unstable_disableValidation: true, unstable_disableValidation: true,
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function Layout({ children }) { export default function Layout({ children }) {
return <>{children}</> return <>{children}</>
......
...@@ -4,7 +4,7 @@ export const unstable_instant = { ...@@ -4,7 +4,7 @@ export const unstable_instant = {
unstable_samples: [{ cookies: [] }], unstable_samples: [{ cookies: [] }],
unstable_disableValidation: true, unstable_disableValidation: true,
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
await connection() await connection()
......
...@@ -4,7 +4,7 @@ export const unstable_instant = { ...@@ -4,7 +4,7 @@ export const unstable_instant = {
unstable_samples: [{ cookies: [] }], unstable_samples: [{ cookies: [] }],
unstable_disableValidation: true, unstable_disableValidation: true,
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
await connection() await connection()
......
...@@ -4,7 +4,7 @@ import { connection } from 'next/server' ...@@ -4,7 +4,7 @@ import { connection } from 'next/server'
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' } 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 // Note that we're inside a root layout with suspense, so we skip the static shell
export async function generateViewport(): Promise<Viewport> { export async function generateViewport(): Promise<Viewport> {
......
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Layout({ children }) { export default async function Layout({ children }) {
return <>{children}</> return <>{children}</>
......
...@@ -4,7 +4,7 @@ import { connection } from 'next/server' ...@@ -4,7 +4,7 @@ import { connection } from 'next/server'
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export async function generateMetadata(): Promise<Metadata> { export async function generateMetadata(): Promise<Metadata> {
await connection() await connection()
......
...@@ -2,7 +2,7 @@ import type { Viewport } from 'next' ...@@ -2,7 +2,7 @@ import type { Viewport } from 'next'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export async function generateViewport(): Promise<Viewport> { export async function generateViewport(): Promise<Viewport> {
await cookies() await cookies()
......
...@@ -2,7 +2,7 @@ import { Suspense } from 'react' ...@@ -2,7 +2,7 @@ import { Suspense } from 'react'
import { connection } from 'next/server' import { connection } from 'next/server'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function SlotPage() { export default function SlotPage() {
return ( return (
......
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function RuntimeLayout({ children }) { export default async function RuntimeLayout({ children }) {
await cookies() await cookies()
......
// Avoid static shell validation -- we only want to test the validation of `prefetch: 'runtime'` here. // Avoid static shell validation -- we only want to test the validation of `prefetch: 'runtime'` here.
export const unstable_instant = false export const unstable_instant = false
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default function DisableStaticShell({ children }) { export default function DisableStaticShell({ children }) {
return <>{children}</> return <>{children}</>
......
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } 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 // 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 // input to a public "use cache" function. The cache doesn't read the cookies
......
...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers' ...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export async function generateMetadata() { export async function generateMetadata() {
await cookies() await cookies()
......
...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers' ...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
async function Runtime() { async function Runtime() {
await cookies() await cookies()
......
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } 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 // This page HAS runtime prefetch enabled. The sync IO (Date.now()) after
// cookies() is invalid here because during a runtime prefetch, cookies() // cookies() is invalid here because during a runtime prefetch, cookies()
......
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
await cookies() await cookies()
......
...@@ -2,7 +2,7 @@ import { connection } from 'next/server' ...@@ -2,7 +2,7 @@ import { connection } from 'next/server'
import { ReactNode } from 'react' import { ReactNode } from 'react'
export const unstable_instant = { level: 'experimental-error' } 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 }) { export default async function Layout({ children }: { children: ReactNode }) {
await connection() await connection()
......
...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers' ...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { connection } from 'next/server' import { connection } from 'next/server'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
await cookies() await cookies()
......
...@@ -4,7 +4,7 @@ import { ReactNode } from 'react' ...@@ -4,7 +4,7 @@ import { ReactNode } from 'react'
// runtime prefetching to handle dynamic data, but the parent layout // runtime prefetching to handle dynamic data, but the parent layout
// above this one gets static prefetching by default and blocks. // above this one gets static prefetching by default and blocks.
export const unstable_instant = { level: 'experimental-error' } 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 }) { export default function InnerLayout({ children }: { children: ReactNode }) {
return ( return (
......
...@@ -3,7 +3,7 @@ import { connection } from 'next/server' ...@@ -3,7 +3,7 @@ import { connection } from 'next/server'
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers' ...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { connection } from 'next/server' import { connection } from 'next/server'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
await cookies() await cookies()
......
...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers' ...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function RuntimeLayout({ children }) { export default async function RuntimeLayout({ children }) {
await cookies() await cookies()
......
...@@ -5,7 +5,7 @@ export const unstable_instant = { ...@@ -5,7 +5,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ cookies: [], params: { param: '123' } }], unstable_samples: [{ cookies: [], params: { param: '123' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ export default async function Page({
params, params,
......
...@@ -5,7 +5,7 @@ export const unstable_instant = { ...@@ -5,7 +5,7 @@ export const unstable_instant = {
level: 'experimental-error', level: 'experimental-error',
unstable_samples: [{ cookies: [], searchParams: { foo: 'bar' } }], unstable_samples: [{ cookies: [], searchParams: { foo: 'bar' } }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ export default async function Page({
searchParams, searchParams,
......
...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers' ...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
export const unstable_instant = { level: 'experimental-error' } export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
async function Runtime() { async function Runtime() {
await cookies() await cookies()
......
...@@ -5,7 +5,7 @@ import { connection } from 'next/server' ...@@ -5,7 +5,7 @@ import { connection } from 'next/server'
// `SubtreeHasPartialPrefetching` hint originates here and must propagate up // `SubtreeHasPartialPrefetching` hint originates here and must propagate up
// through the /a/b and /a layouts to the root for the scheduler to downgrade a // through the /a/b and /a layouts to the root for the scheduler to downgrade a
// `prefetch={true}` link into a partial (PPR) prefetch. // `prefetch={true}` link into a partial (PPR) prefetch.
export const unstable_prefetch = 'partial' export const prefetch = 'partial'
export default function Page() { export default function Page() {
return ( return (
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
// Note: Partial Prefetching is NOT enabled globally. The target route opts // 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, cacheComponents: true,
} }
......
...@@ -18,7 +18,7 @@ describe('partial prefetching - deep subtree-hint propagation', () => { ...@@ -18,7 +18,7 @@ describe('partial prefetching - deep subtree-hint propagation', () => {
// even if the implementation details change. // even if the implementation details change.
// //
// The route `/a/b/c` opts into Partial Prefetching on its leaf page via // 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 // `SubtreeHasPartialPrefetching` hint originates on that leaf and must
// propagate up through the `/a/b` and `/a` layout segments to the ROOT of // 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 // the route tree, because the prefetch scheduler reads the hint at the root
......
...@@ -4,7 +4,7 @@ import { connection } from 'next/server' ...@@ -4,7 +4,7 @@ import { connection } from 'next/server'
// Opts this route into partial prefetching at the segment level, without the // Opts this route into partial prefetching at the segment level, without the
// global `partialPrefetching` flag. A `prefetch={true}` link should prefetch // global `partialPrefetching` flag. A `prefetch={true}` link should prefetch
// the static shell but never the dynamic data. // the static shell but never the dynamic data.
export const unstable_prefetch = 'partial' export const prefetch = 'partial'
export default function Page() { export default function Page() {
return ( return (
......
...@@ -38,7 +38,7 @@ describe('partial prefetching segment config', () => { ...@@ -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 let page: Playwright.Page
const browser = await next.browser('/', { const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) { beforePageLoad(p: Playwright.Page) {
...@@ -49,7 +49,7 @@ describe('partial prefetching segment config', () => { ...@@ -49,7 +49,7 @@ describe('partial prefetching segment config', () => {
// Reveal the link to trigger its prefetch. The Link has prefetch={true}, // Reveal the link to trigger its prefetch. The Link has prefetch={true},
// and the target route opts into partial prefetching via // 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 // include the static shell, but NOT the dynamic data — even though the
// global config does not enable partial prefetching. // global config does not enable partial prefetching.
await act(async () => { await act(async () => {
......
...@@ -3,7 +3,7 @@ import { ReactNode } from 'react' ...@@ -3,7 +3,7 @@ import { ReactNode } from 'react'
export const unstable_instant = { export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'test', value: null }] }], 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 }) { export default function Layout({ children }: { children: ReactNode }) {
return <div>{children}</div> return <div>{children}</div>
......
...@@ -5,7 +5,7 @@ import { connection } from 'next/server' ...@@ -5,7 +5,7 @@ import { connection } from 'next/server'
export const unstable_instant = { export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'test', value: null }] }], unstable_samples: [{ cookies: [{ name: 'test', value: null }] }],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page() { export default async function Page() {
return ( return (
......
...@@ -12,7 +12,7 @@ export const unstable_instant = { ...@@ -12,7 +12,7 @@ export const unstable_instant = {
}, },
], ],
} }
export const unstable_prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
export default async function Page({ export default async function Page({
searchParams, searchParams,
......
...@@ -2,7 +2,7 @@ import { Suspense } from 'react' ...@@ -2,7 +2,7 @@ import { Suspense } from 'react'
type Params = { id: string } 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 // the global `partialPrefetching: 'unstable_eager'` in next.config, which makes
// it eager — so the App Shells skip does NOT apply. // it eager — so the App Shells skip does NOT apply.
export function generateStaticParams() { export function generateStaticParams() {
......
...@@ -5,7 +5,7 @@ const nextConfig: NextConfig = { ...@@ -5,7 +5,7 @@ const nextConfig: NextConfig = {
// Opt the whole app into Partial Prefetching in "eager" mode. Every route's // Opt the whole app into Partial Prefetching in "eager" mode. Every route's
// default prefetch config becomes 'unstable_eager', so under App Shells the // default prefetch config becomes 'unstable_eager', so under App Shells the
// per-link Speculative prefetch is NOT skipped — even for routes with no // per-link Speculative prefetch is NOT skipped — even for routes with no
// per-segment `unstable_prefetch` export. // per-segment `prefetch` export.
partialPrefetching: 'unstable_eager', partialPrefetching: 'unstable_eager',
experimental: { experimental: {
prefetchInlining: true, prefetchInlining: true,
......
...@@ -3,12 +3,12 @@ import { Suspense } from 'react' ...@@ -3,12 +3,12 @@ import { Suspense } from 'react'
type Params = { id: string } type Params = { id: string }
// Combines both segment-level opt-ins: `unstable_instant` (which on its own // 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 // 'unstable_eager' wins: the segment is marked eager, so under App Shells the
// per-link Speculative prefetch still fires and the param-specific content // per-link Speculative prefetch still fires and the param-specific content
// below IS prefetched. // below IS prefetched.
export const unstable_instant = true export const unstable_instant = true
export const unstable_prefetch = 'unstable_eager' export const prefetch = 'unstable_eager'
export function generateStaticParams() { export function generateStaticParams() {
return [{ id: '1' }, { id: '2' }, { id: '3' }] 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