Unverified Commit bc48ef76 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Unify appShells flag with Partial Prefetching (#95415)

The experimental `appShells` flag was added while the feature was being
developed. It was not meant to be a public-facing flag.

Some of the behavior that was gated behind the `appShells` flag is
purely an optimization and can be landed without any gate.

There are also some behaviors that we don't want to turn on unless
you've opted into the new prefetching model via Partial Prefetching.
Arguably these too are internal optimizations, but because they can
change the number of requests that are made to the server (e.g. one
request for the shell, another for the page data), we will gate these
behind Partial Prefetching to minimize the impact on existing
applications.

The result is that until you opt into Partial Prefetching, you should
not see any meaningfully detrimental impact to prefetching costs,
regardless of how your app is structured.
parent 491f7809
...@@ -392,7 +392,6 @@ export function getDefineEnv({ ...@@ -392,7 +392,6 @@ export function getDefineEnv({
config.experimental.optimisticRouting ?? false, config.experimental.optimisticRouting ?? false,
'process.env.__NEXT_INSTRUMENTATION_CLIENT_ROUTER_TRANSITION_EVENTS': 'process.env.__NEXT_INSTRUMENTATION_CLIENT_ROUTER_TRANSITION_EVENTS':
config.experimental.instrumentationClientRouterTransitionEvents ?? false, config.experimental.instrumentationClientRouterTransitionEvents ?? false,
'process.env.__NEXT_APP_SHELLS': config.experimental.appShells ?? false,
'process.env.__NEXT_VARY_PARAMS': config.experimental.varyParams ?? false, 'process.env.__NEXT_VARY_PARAMS': config.experimental.varyParams ?? false,
'process.env.__NEXT_EXPOSE_TESTING_API': 'process.env.__NEXT_EXPOSE_TESTING_API':
dev || config.experimental.exposeTestingApiInProductionBuild === true, dev || config.experimental.exposeTestingApiInProductionBuild === true,
......
...@@ -929,7 +929,6 @@ export async function handler( ...@@ -929,7 +929,6 @@ export async function handler(
useCacheTimeout: nextConfig.experimental.useCacheTimeout, useCacheTimeout: nextConfig.experimental.useCacheTimeout,
cachedNavigations: cachedNavigations:
nextConfig.experimental.cachedNavigations ?? false, nextConfig.experimental.cachedNavigations ?? false,
appShells: nextConfig.experimental.appShells,
clientTraceMetadata: clientTraceMetadata:
nextConfig.experimental.clientTraceMetadata || ([] as any), nextConfig.experimental.clientTraceMetadata || ([] as any),
clientParamParsingOrigins: clientParamParsingOrigins:
......
...@@ -179,7 +179,6 @@ async function requestHandler( ...@@ -179,7 +179,6 @@ async function requestHandler(
serverComponentsHmrCancellation: false, serverComponentsHmrCancellation: false,
useCacheTimeout: nextConfig.experimental.useCacheTimeout, useCacheTimeout: nextConfig.experimental.useCacheTimeout,
cachedNavigations: nextConfig.experimental.cachedNavigations ?? false, cachedNavigations: nextConfig.experimental.cachedNavigations ?? false,
appShells: nextConfig.experimental.appShells,
clientTraceMetadata: clientTraceMetadata:
nextConfig.experimental.clientTraceMetadata || ([] as any), nextConfig.experimental.clientTraceMetadata || ([] as any),
clientParamParsingOrigins: clientParamParsingOrigins:
......
...@@ -2629,10 +2629,11 @@ export async function fetchSegmentPrefetchesUsingDynamicRequest( ...@@ -2629,10 +2629,11 @@ export async function fetchSegmentPrefetchesUsingDynamicRequest(
// staleAt that corresponds to whatever payload the spawned entries get // staleAt that corresponds to whatever payload the spawned entries get
// filled with below. // filled with below.
let staleAtForSpawnedEntries = staleAt let staleAtForSpawnedEntries = staleAt
if (!process.env.__NEXT_APP_SHELLS || cacheData === null) { if (cacheData === null) {
// NOTE: cacheData is always set when Cached Navigations is enabled, and // No shell can be extracted without cache metadata (only present when
// therefore when App Shells is enabled. This null check can be removed // Cached Navigations is enabled). For routes without a distinct App Shell
// when those flags fully land. // the extraction below is a no-op anyway (`resolveShellStageData` returns
// null), so this just short-circuits that case.
serverDataThatSatisfiesSpawnedEntries = serverData serverDataThatSatisfiesSpawnedEntries = serverData
} else { } else {
const shellStageData = await resolveShellStageData( const shellStageData = await resolveShellStageData(
......
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
import { matchSegment } from '../match-segments' import { matchSegment } from '../match-segments'
import { import {
readOrCreateRouteCacheEntry, readOrCreateRouteCacheEntry,
readRouteCacheEntry,
readOrCreateSegmentCacheEntry, readOrCreateSegmentCacheEntry,
fetchRouteOnCacheMiss, fetchRouteOnCacheMiss,
fetchSegmentsOnCacheMiss, fetchSegmentsOnCacheMiss,
...@@ -575,9 +576,24 @@ function processQueueInMicrotask() { ...@@ -575,9 +576,24 @@ function processQueueInMicrotask() {
continue continue
case PrefetchTaskExitStatus.Done: case PrefetchTaskExitStatus.Done:
if (task.phase === PrefetchPhase.RouteTree) { if (task.phase === PrefetchPhase.RouteTree) {
// Finished prefetching the route tree. If App Shells are enabled, // Finished prefetching the route tree. The two-phase (Shell then
// run the Shell phase next; otherwise go straight to Speculative. // Speculative) flow only applies to routes that have opted into
task.phase = process.env.__NEXT_APP_SHELLS // Partial Prefetching — either globally via the `partialPrefetching`
// config or per segment (`instant`, `prefetch: 'partial'`,
// `'unstable_eager'`, or `'allow-runtime'`), all surfaced as the
// `SubtreeHasPartialPrefetching` hint on the route tree. Every other
// route skips the Shell phase and goes straight to Speculative.
//
// The route entry is fulfilled at this point (the RouteTree phase
// just completed), so its prefetch hints are available.
const route = readRouteCacheEntry(now, task.key)
const routeHasPartialPrefetching =
route !== null &&
route.status === EntryStatus.Fulfilled &&
(route.tree.prefetchHints &
PrefetchHint.SubtreeHasPartialPrefetching) !==
0
task.phase = routeHasPartialPrefetching
? PrefetchPhase.Shell ? PrefetchPhase.Shell
: PrefetchPhase.Speculative : PrefetchPhase.Speculative
heapResift(taskHeap, task) heapResift(taskHeap, task)
...@@ -2051,17 +2067,13 @@ export function subtreeHasSpeculativePrefetch( ...@@ -2051,17 +2067,13 @@ export function subtreeHasSpeculativePrefetch(
fetchStrategy: FetchStrategy, fetchStrategy: FetchStrategy,
prefetchHints: number prefetchHints: number
): boolean { ): boolean {
if (!process.env.__NEXT_APP_SHELLS) {
// When App Shells is disabled, all prefetches implicitly include the
// speculative (non-shell) part of the target.
return true
}
return ( return (
// Check if this is a "full" prefetch (<Link prefetch={true}>). // Check if this is a "full" prefetch (<Link prefetch={true}>).
fetchStrategy === FetchStrategy.Full || fetchStrategy === FetchStrategy.Full ||
// Check if something in this subtree is configured to be eagerly // Check if something in this subtree is configured to be eagerly
// prefetched at the route level. // prefetched at the route level. Segments that don't opt into Partial
// Prefetching are marked eager, so a route without any Partial Prefetching
// still speculatively prefetches everything.
(prefetchHints & PrefetchHint.SubtreeHasEagerPrefetch) !== 0 (prefetchHints & PrefetchHint.SubtreeHasEagerPrefetch) !== 0
) )
} }
......
...@@ -519,7 +519,6 @@ async function exportAppImpl( ...@@ -519,7 +519,6 @@ async function exportAppImpl(
authInterrupts: !!nextConfig.experimental.authInterrupts, authInterrupts: !!nextConfig.experimental.authInterrupts,
useCacheTimeout: nextConfig.experimental.useCacheTimeout, useCacheTimeout: nextConfig.experimental.useCacheTimeout,
cachedNavigations: nextConfig.experimental.cachedNavigations ?? false, cachedNavigations: nextConfig.experimental.cachedNavigations ?? false,
appShells: nextConfig.experimental.appShells,
maxPostponedStateSizeBytes: parseMaxPostponedStateSize( maxPostponedStateSizeBytes: parseMaxPostponedStateSize(
nextConfig.experimental.maxPostponedStateSize nextConfig.experimental.maxPostponedStateSize
), ),
......
...@@ -123,7 +123,12 @@ async function createFlightRouterStateFromLoaderTreeImpl( ...@@ -123,7 +123,12 @@ async function createFlightRouterStateFromLoaderTreeImpl(
} else if (prefetchConfig === 'force-disabled') { } else if (prefetchConfig === 'force-disabled') {
prefetchHints |= PrefetchHint.PrefetchDisabled prefetchHints |= PrefetchHint.PrefetchDisabled
} else if (prefetchConfig === 'allow-runtime') { } else if (prefetchConfig === 'allow-runtime') {
prefetchHints |= PrefetchHint.HasRuntimePrefetch // 'allow-runtime' participates in the two-phase (Shell then Speculative)
// prefetch flow, so it counts as Partial Prefetching. HasRuntimePrefetch
// additionally marks it as needing a runtime request pass.
prefetchHints |=
PrefetchHint.HasRuntimePrefetch |
PrefetchHint.SubtreeHasPartialPrefetching
} }
// Mark the segment as "eager" unless its effective prefetch strategy is // Mark the segment as "eager" unless its effective prefetch strategy is
......
...@@ -916,7 +916,7 @@ export enum ValidationPrefetchKind { ...@@ -916,7 +916,7 @@ export enum ValidationPrefetchKind {
Shell = 1, Shell = 1,
// TODO(app-shells): validate speculative prefetches // TODO(app-shells): validate speculative prefetches
// Speculative = 2, // Speculative = 2,
/** Pre-appShells behavior. */ /** Behavior when Partial Prefetching is not enabled. */
LegacySpeculative = 3, LegacySpeculative = 3,
} }
......
...@@ -170,7 +170,6 @@ export interface RenderOptsPartial { ...@@ -170,7 +170,6 @@ export interface RenderOptsPartial {
serverComponentsHmrCancellation?: boolean serverComponentsHmrCancellation?: boolean
useCacheTimeout: number useCacheTimeout: number
cachedNavigations: boolean | 'allow-runtime' cachedNavigations: boolean | 'allow-runtime'
appShells: ExperimentalConfig['appShells']
/** /**
* The maximum size (in bytes) of the postponed state body for PPR resume * The maximum size (in bytes) of the postponed state body for PPR resume
......
...@@ -602,7 +602,6 @@ export default abstract class Server< ...@@ -602,7 +602,6 @@ export default abstract class Server<
useCacheTimeout: this.nextConfig.experimental.useCacheTimeout, useCacheTimeout: this.nextConfig.experimental.useCacheTimeout,
cachedNavigations: cachedNavigations:
this.nextConfig.experimental.cachedNavigations ?? false, this.nextConfig.experimental.cachedNavigations ?? false,
appShells: this.nextConfig.experimental.appShells,
maxPostponedStateSizeBytes: parseMaxPostponedStateSize( maxPostponedStateSizeBytes: parseMaxPostponedStateSize(
this.nextConfig.experimental.maxPostponedStateSize this.nextConfig.experimental.maxPostponedStateSize
), ),
......
...@@ -229,7 +229,6 @@ export const experimentalSchema = { ...@@ -229,7 +229,6 @@ export const experimentalSchema = {
useOffline: z.boolean().optional(), useOffline: z.boolean().optional(),
optimisticRouting: z.boolean().optional(), optimisticRouting: z.boolean().optional(),
instrumentationClientRouterTransitionEvents: z.boolean().optional(), instrumentationClientRouterTransitionEvents: z.boolean().optional(),
appShells: z.boolean().optional(),
varyParams: z.boolean().optional(), varyParams: z.boolean().optional(),
prefetchInlining: z prefetchInlining: z
.union([ .union([
......
...@@ -512,14 +512,6 @@ export interface ExperimentalConfig { ...@@ -512,14 +512,6 @@ export interface ExperimentalConfig {
useOffline?: boolean useOffline?: boolean
optimisticRouting?: boolean optimisticRouting?: boolean
instrumentationClientRouterTransitionEvents?: boolean instrumentationClientRouterTransitionEvents?: boolean
/**
* Enables App Shell prefetching: a route's reusable, param-free loading
* state is prefetched once per session and served instantly for any
* concrete navigation. Routes marked as fully static (no per-request
* server work) are unaffected; the App Shell phase only runs for
* runtime-prefetchable routes.
*/
appShells?: boolean
varyParams?: boolean varyParams?: boolean
prefetchInlining?: prefetchInlining?:
| boolean | boolean
...@@ -2286,7 +2278,6 @@ export interface NextConfigRuntime { ...@@ -2286,7 +2278,6 @@ export interface NextConfigRuntime {
| 'dynamicOnHover' | 'dynamicOnHover'
| 'useOffline' | 'useOffline'
| 'optimisticRouting' | 'optimisticRouting'
| 'appShells'
| 'inlineCss' | 'inlineCss'
| 'prefetchInlining' | 'prefetchInlining'
| 'authInterrupts' | 'authInterrupts'
...@@ -2356,7 +2347,6 @@ export function getNextConfigRuntime( ...@@ -2356,7 +2347,6 @@ export function getNextConfigRuntime(
dynamicOnHover: ex.dynamicOnHover, dynamicOnHover: ex.dynamicOnHover,
useOffline: ex.useOffline, useOffline: ex.useOffline,
optimisticRouting: ex.optimisticRouting, optimisticRouting: ex.optimisticRouting,
appShells: ex.appShells,
inlineCss: ex.inlineCss, inlineCss: ex.inlineCss,
prefetchInlining: ex.prefetchInlining, prefetchInlining: ex.prefetchInlining,
authInterrupts: ex.authInterrupts, authInterrupts: ex.authInterrupts,
......
...@@ -570,35 +570,6 @@ function assignDefaultsAndValidate( ...@@ -570,35 +570,6 @@ function assignDefaultsAndValidate(
) )
} }
if (result.experimental.appShells) {
// App Shells is tested in combination with the experimental flags it
// expects to ship alongside. All of these are on track to become
// defaults, so we don't support enabling App Shells against arbitrary
// subsets of them — the validation goes away once each becomes a
// default.
// Note: `prefetchInlining` is intentionally NOT required. App Shells works
// correctly whether or not prefetch inlining is enabled, so disabling it
// (e.g. to exercise non-inlined prefetch paths) must not force App Shells off.
const missing: string[] = []
if (!result.cacheComponents) {
missing.push('`cacheComponents`')
}
if (!result.experimental.varyParams) {
missing.push('`experimental.varyParams`')
}
if (!result.experimental.optimisticRouting) {
missing.push('`experimental.optimisticRouting`')
}
if (!result.experimental.cachedNavigations) {
missing.push('`experimental.cachedNavigations`')
}
if (missing.length > 0) {
throw new Error(
`\`experimental.appShells\` requires the following to also be enabled: ${missing.join(', ')}. Please update your ${configFileName} accordingly.`
)
}
}
if (result.experimental.ppr) { if (result.experimental.ppr) {
throw new HardDeprecatedConfigError( throw new HardDeprecatedConfigError(
`\`experimental.ppr\` has been merged into \`cacheComponents\`. The Partial Prerendering feature is still available, but is now enabled via \`cacheComponents\`. Please update your ${configFileName} accordingly.` `\`experimental.ppr\` has been merged into \`cacheComponents\`. The Partial Prerendering feature is still available, but is now enabled via \`cacheComponents\`. Please update your ${configFileName} accordingly.`
...@@ -2327,32 +2298,6 @@ function enforceExperimentalFeatures( ...@@ -2327,32 +2298,6 @@ function enforceExperimentalFeatures(
config.experimental.cachedNavigations = true config.experimental.cachedNavigations = true
} }
// Enable appShells by default when cacheComponents is enabled, unless
// explicitly disabled. App Shells builds on Cache Components rendering, so
// the two features are tied together: we only flip the default for projects
// that are already using Cache Components. Done silently for the same reasons
// as the cachedNavigations default above.
//
// We only auto-enable when App Shells's required dependencies are satisfied.
// If a project has explicitly disabled one of them, we leave App Shells off
// rather than force it on — otherwise the validation in
// `assignDefaultsAndValidate` would turn a previously-valid config into a
// hard error. Users who want App Shells in that situation can still enable it
// explicitly and get the actionable validation message. `prefetchInlining` is
// intentionally not part of this gate (App Shells works without it). This runs
// after the cachedNavigations default above so that dependency is already set.
// TODO: Remove this once appShells is unconditionally the default.
if (
config.cacheComponents &&
config.experimental.varyParams !== false &&
config.experimental.optimisticRouting !== false &&
config.experimental.cachedNavigations !== false &&
(config.experimental.appShells === undefined ||
(isDefaultConfig && !config.experimental.appShells))
) {
config.experimental.appShells = true
}
// appNewScrollHandler defaults to `true`. The env var lets us opt back out to // appNewScrollHandler defaults to `true`. The env var lets us opt back out to
// keep test coverage of the old scroll handler on the non-experimental CI // keep test coverage of the old scroll handler on the non-experimental CI
// shards. Like the other env-var experimental toggles, opting out is surfaced // shards. Like the other env-var experimental toggles, opting out is surfaced
......
...@@ -358,7 +358,7 @@ function createStaticPrerenderParams( ...@@ -358,7 +358,7 @@ function createStaticPrerenderParams(
// All params are static. // All params are static.
const { stagedRendering } = prerenderStore const { stagedRendering } = prerenderStore
if (process.env.__NEXT_APP_SHELLS && stagedRendering) { if (stagedRendering) {
// Even if all params are static, we need to exclude them from the app shell // Even if all params are static, we need to exclude them from the app shell
// by delaying them to the static stage. However, root params are allowed in shells, // by delaying them to the static stage. However, root params are allowed in shells,
// so if all the params are root params, they can be included as well. // so if all the params are root params, they can be included as well.
...@@ -458,8 +458,8 @@ function createRuntimePrerenderParams( ...@@ -458,8 +458,8 @@ function createRuntimePrerenderParams(
// We don't have fallbackParams in runtime prerenders, so we don't know // We don't have fallbackParams in runtime prerenders, so we don't know
// when params are static. However, root params are static by definition, // when params are static. However, root params are static by definition,
// so we can at least check for that. // so we can at least check for that.
// Note that resolving them without a delay is also valid in `appShells`, // Note that resolving them without a delay is valid because root params are
// because root params are allowed in shells. // allowed in shells.
if (allParamsAreRootParams(underlyingParams, workUnitStore.rootParams)) { if (allParamsAreRootParams(underlyingParams, workUnitStore.rootParams)) {
return makeUntrackedParams(userspaceParams) return makeUntrackedParams(userspaceParams)
} }
...@@ -583,10 +583,7 @@ function createStagedRenderParamsImpl( ...@@ -583,10 +583,7 @@ function createStagedRenderParamsImpl(
// If we're rendering with shells, even static params must be delayed to exclude them from the shell. // If we're rendering with shells, even static params must be delayed to exclude them from the shell.
// However, root params are allowed in shells, so if all the params are root params, they can be included as well. // However, root params are allowed in shells, so if all the params are root params, they can be included as well.
if ( if (!allParamsAreRootParams(underlyingParams, workUnitStore.rootParams)) {
process.env.__NEXT_APP_SHELLS &&
!allParamsAreRootParams(underlyingParams, workUnitStore.rootParams)
) {
// For a dynamic request we generally want to recover a static shell, // For a dynamic request we generally want to recover a static shell,
// so static params can resolve in the static stage, because session // so static params can resolve in the static stage, because session
// shells are handled with a separate render. // shells are handled with a separate render.
......
...@@ -204,11 +204,6 @@ export default class ResponseCache implements ResponseCacheBase { ...@@ -204,11 +204,6 @@ export default class ResponseCache implements ResponseCacheBase {
routeKind: RouteKind routeKind: RouteKind
isOnDemandRevalidate?: boolean isOnDemandRevalidate?: boolean
isPrefetch?: boolean isPrefetch?: boolean
/**
* Whether the `appShells` experimental flag is enabled. Gates the
* prefetch-miss-serves-fallback-shell behavior in `handleGet`.
*/
appShells?: boolean
incrementalCache: IncrementalResponseCache incrementalCache: IncrementalResponseCache
isRoutePPREnabled?: boolean isRoutePPREnabled?: boolean
isFallback?: boolean isFallback?: boolean
...@@ -270,7 +265,6 @@ export default class ResponseCache implements ResponseCacheBase { ...@@ -270,7 +265,6 @@ export default class ResponseCache implements ResponseCacheBase {
isFallback = false, isFallback = false,
isRoutePPREnabled = false, isRoutePPREnabled = false,
isPrefetch = false, isPrefetch = false,
appShells = false,
waitUntil, waitUntil,
routeKind, routeKind,
invocationID, invocationID,
...@@ -288,7 +282,6 @@ export default class ResponseCache implements ResponseCacheBase { ...@@ -288,7 +282,6 @@ export default class ResponseCache implements ResponseCacheBase {
isFallback, isFallback,
isRoutePPREnabled, isRoutePPREnabled,
isPrefetch, isPrefetch,
appShells,
routeKind, routeKind,
invocationID, invocationID,
}, },
...@@ -331,7 +324,6 @@ export default class ResponseCache implements ResponseCacheBase { ...@@ -331,7 +324,6 @@ export default class ResponseCache implements ResponseCacheBase {
isFallback: boolean isFallback: boolean
isRoutePPREnabled: boolean isRoutePPREnabled: boolean
isPrefetch: boolean isPrefetch: boolean
appShells: boolean
routeKind: RouteKind routeKind: RouteKind
invocationID: string | undefined invocationID: string | undefined
}, },
...@@ -381,13 +373,8 @@ export default class ResponseCache implements ResponseCacheBase { ...@@ -381,13 +373,8 @@ export default class ResponseCache implements ResponseCacheBase {
// wins would depend purely on request timing. Running the generator // wins would depend purely on request timing. Running the generator
// directly lets every prefetch segment take the same fallback-shell path, // directly lets every prefetch segment take the same fallback-shell path,
// independent of any concurrent background upgrade. // independent of any concurrent background upgrade.
//
// Gated on `appShells`: with the flag off, prefetch misses keep the
// previous batch-join behavior so existing suites are unaffected.
const incrementalResponseCacheEntry = const incrementalResponseCacheEntry =
context.isPrefetch && context.isPrefetch && previousIncrementalCacheEntry === null
context.appShells &&
previousIncrementalCacheEntry === null
? await this.handleRevalidate( ? await this.handleRevalidate(
key, key,
context.incrementalCache, context.incrementalCache,
......
...@@ -1136,28 +1136,20 @@ export abstract class RouteModule< ...@@ -1136,28 +1136,20 @@ export abstract class RouteModule<
isMinimalMode: boolean isMinimalMode: boolean
}) { }) {
const responseCache = this.getResponseCache(req) const responseCache = this.getResponseCache(req)
// The prefetch-serves-fallback-shell behavior is gated behind the
// `appShells` experimental flag. When it's off, Next.js Segment Cache
// prefetches keep the previous (non-prefetch) response-cache behavior so
// existing suites that incidentally depend on it are unaffected.
const appShells = nextConfig.experimental.appShells === true
const cacheEntry = await responseCache.get(cacheKey, responseGenerator, { const cacheEntry = await responseCache.get(cacheKey, responseGenerator, {
routeKind, routeKind,
isFallback, isFallback,
isRoutePPREnabled, isRoutePPREnabled,
isOnDemandRevalidate, isOnDemandRevalidate,
appShells,
// A Next.js Segment Cache prefetch uses the `Next-Router-Prefetch` // A Next.js Segment Cache prefetch uses the `Next-Router-Prefetch`
// header (surfaced as the `isPrefetchRSCRequest` request meta), not the // header (surfaced as the `isPrefetchRSCRequest` request meta), not the
// standard browser `purpose: prefetch` header. Recognize both so the // standard browser `purpose: prefetch` header. Recognize both so the
// response cache treats segment prefetches as prefetches — most // response cache treats segment prefetches as prefetches — most
// importantly, so a prefetch that misses serves a fallback shell rather // importantly, so a prefetch that misses serves a fallback shell rather
// than joining an in-flight background (concrete) revalidation. The // than joining an in-flight background (concrete) revalidation.
// Next.js-prefetch arm is gated on `appShells`; with the flag off, only
// the standard browser prefetch header is recognized (unchanged).
isPrefetch: isPrefetch:
req.headers.purpose === 'prefetch' || req.headers.purpose === 'prefetch' ||
(appShells && getRequestMeta(req, 'isPrefetchRSCRequest') === true), getRequestMeta(req, 'isPrefetchRSCRequest') === true,
// Use x-invocation-id header to scope the in-memory cache to a single // Use x-invocation-id header to scope the in-memory cache to a single
// revalidation request in minimal mode. // revalidation request in minimal mode.
invocationID: req.headers['x-invocation-id'] as string | undefined, invocationID: req.headers['x-invocation-id'] as string | undefined,
......
...@@ -184,10 +184,11 @@ export const enum PrefetchHint { ...@@ -184,10 +184,11 @@ export const enum PrefetchHint {
// This segment has a runtime prefetch enabled (via instant with // This segment has a runtime prefetch enabled (via instant with
// prefetch: 'runtime'). Per-segment only, does not propagate to ancestors. // prefetch: 'runtime'). Per-segment only, does not propagate to ancestors.
HasRuntimePrefetch = 0b00001, HasRuntimePrefetch = 0b00001,
// This segment or one of its descendants opts into Partial Prefetching. // This segment or one of its descendants opts into Partial Prefetching, i.e.
// Currently set when a truthy instant config is present on any // uses the two-phase (Shell then Speculative) prefetch flow. Set when a
// segment in the subtree (regardless of prefetch mode). Propagates upward // truthy instant config is present, or `prefetch` is 'partial',
// so the root segment reflects the entire subtree. // 'unstable_eager', or 'allow-runtime'. Propagates upward so the root segment
// reflects the entire subtree.
SubtreeHasPartialPrefetching = 0b00010, SubtreeHasPartialPrefetching = 0b00010,
// This segment itself has a loading.tsx boundary. // This segment itself has a loading.tsx boundary.
SegmentHasLoadingBoundary = 0b00100, SegmentHasLoadingBoundary = 0b00100,
......
...@@ -9,10 +9,6 @@ const nextConfig = { ...@@ -9,10 +9,6 @@ const nextConfig = {
// shell. // shell.
partialPrefetching: true, partialPrefetching: true,
experimental: { experimental: {
// App Shells must be enabled for the shell restriction to apply — with it
// off, every prefetch implicitly includes the speculative (non-shell) part
// of the target, so there is nothing to restrict.
appShells: true,
// Enable the testing API in production builds for these tests. // Enable the testing API in production builds for these tests.
exposeTestingApiInProductionBuild: true, exposeTestingApiInProductionBuild: true,
prefetchInlining: false, prefetchInlining: false,
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
const nextConfig = { const nextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { experimental: {
// TODO(appShells): migrate this test to the two-phase (app shell +
// per-page data) prefetch behavior, then remove this override. See #94516.
appShells: false,
exposeTestingApiInProductionBuild: true, exposeTestingApiInProductionBuild: true,
prefetchInlining: false, prefetchInlining: false,
}, },
......
/** /**
* @type {import('next').NextConfig} * @type {import('next').NextConfig}
*/ */
const nextConfig = { const nextConfig = {}
experimental: {
// TODO(appShells): migrate this test to the two-phase (app shell +
// per-page data) prefetch behavior, then remove this override. See #94516.
appShells: false,
},
}
module.exports = nextConfig module.exports = nextConfig
...@@ -11,7 +11,6 @@ const nextConfig: NextConfig = { ...@@ -11,7 +11,6 @@ const nextConfig: NextConfig = {
prefetchInlining: true, prefetchInlining: true,
optimisticRouting: true, optimisticRouting: true,
cachedNavigations: true, cachedNavigations: true,
appShells: true,
varyParams: true, varyParams: true,
}, },
} }
......
...@@ -2,6 +2,11 @@ import { Suspense } from 'react' ...@@ -2,6 +2,11 @@ import { Suspense } from 'react'
type Params = { id: string } type Params = { id: string }
// Opt into Partial Prefetching so the fully-static route participates in the
// App Shell flow: its shell prefix is extracted and cached at the Fallback
// vary path, reusable for any param.
export const prefetch = 'partial'
// This page is fully static: no cookies, no `connection()`, no other dynamic // This page is fully static: no cookies, no `connection()`, no other dynamic
// data. All params are statically known via `generateStaticParams`, so the // data. All params are statically known via `generateStaticParams`, so the
// page is prerendered for every URL at build time. With default prefetch // page is prerendered for every URL at build time. With default prefetch
......
...@@ -3,6 +3,11 @@ import { cacheLife } from 'next/cache' ...@@ -3,6 +3,11 @@ import { cacheLife } from 'next/cache'
type Params = { id: string } type Params = { id: string }
// Opt into Partial Prefetching so the fully-static route participates in the
// App Shell flow: its shell prefix is extracted and cached at the Fallback
// vary path, reusable for any param.
export const prefetch = 'partial'
// This page is fully static: all params are statically known via // This page is fully static: all params are statically known via
// `generateStaticParams`, so the page is prerendered for every URL at build // `generateStaticParams`, so the page is prerendered for every URL at build
// time. It mixes cached content with different stale times. Cached content // time. It mixes cached content with different stale times. Cached content
......
...@@ -3,6 +3,11 @@ import { Suspense } from 'react' ...@@ -3,6 +3,11 @@ import { Suspense } from 'react'
type Params = { id: string } type Params = { id: string }
// Opt into Partial Prefetching so the fully-static route participates in the
// App Shell flow: its shell prefix is extracted and cached at the Fallback
// vary path, reusable for any param.
export const prefetch = 'partial'
// This page is fully static: no cookies, no `connection()`, no other dynamic // This page is fully static: no cookies, no `connection()`, no other dynamic
// data. All params are statically known via `generateStaticParams`, so the // data. All params are statically known via `generateStaticParams`, so the
// page is prerendered for every URL at build time. With default prefetch // page is prerendered for every URL at build time. With default prefetch
......
...@@ -6,7 +6,6 @@ const nextConfig: NextConfig = { ...@@ -6,7 +6,6 @@ const nextConfig: NextConfig = {
prefetchInlining: true, prefetchInlining: true,
optimisticRouting: true, optimisticRouting: true,
cachedNavigations: true, cachedNavigations: true,
appShells: true,
varyParams: true, varyParams: true,
}, },
} }
......
...@@ -253,21 +253,16 @@ describe('App Shell prefetching', () => { ...@@ -253,21 +253,16 @@ describe('App Shell prefetching', () => {
}) })
const act = createRouterAct(page, { includeAppShellRequests: true }) const act = createRouterAct(page, { includeAppShellRequests: true })
// Reveal the LinkAccordion for /static-posts/1. Two prefetch responses // Reveal the LinkAccordion for /static-posts/1. The route is fully static
// fire: one for the per-segment static prefetch of /static-posts/1 // and doesn't opt into Partial Prefetching, so there's no separate runtime
// (which contains the resolved page content + the shell above the // shell prefetch — a single per-segment static prefetch fires, carrying the
// params boundary), and one for the runtime shell prefetch (which the // resolved page content plus the shell prefix above the params boundary
// server may return either as a truncated shell or as the full // (with a byte offset the client uses to extract and cache the shell).
// prerender that the client extracts a shell prefix from). Both
// responses contain the "App shell for static posts" substring.
await act(async () => { await act(async () => {
await browser await browser
.elementByCss('input[data-link-accordion="/static-posts/1"]') .elementByCss('input[data-link-accordion="/static-posts/1"]')
.click() .click()
}, [ }, [{ includes: 'App shell for static posts' }])
{ includes: 'App shell for static posts' },
{ includes: 'App shell for static posts' },
])
// Click the link to /static-posts/124 — a different param than what // Click the link to /static-posts/124 — a different param than what
// was prefetched, rendered with prefetch={false}. The cached App // was prefetched, rendered with prefetch={false}. The cached App
...@@ -363,16 +358,14 @@ describe('App Shell prefetching', () => { ...@@ -363,16 +358,14 @@ describe('App Shell prefetching', () => {
const act = createRouterAct(page, { includeAppShellRequests: true }) const act = createRouterAct(page, { includeAppShellRequests: true })
// Reveal the LinkAccordion for /static-short-stale/1. Like the // Reveal the LinkAccordion for /static-short-stale/1. Like the
// static-posts route, two prefetch responses fire: the per-segment static // static-posts route, it's fully static and opts into Partial Prefetching,
// prefetch of /static-short-stale/1 and the runtime shell prefetch. // so a single per-segment static prefetch fires, carrying the shell prefix
// that the client extracts and caches at the Fallback vary path.
await act(async () => { await act(async () => {
await browser await browser
.elementByCss('input[data-link-accordion="/static-short-stale/1"]') .elementByCss('input[data-link-accordion="/static-short-stale/1"]')
.click() .click()
}, [ }, [{ includes: 'App shell for static short-stale posts' }])
{ includes: 'App shell for static short-stale posts' },
{ includes: 'App shell for static short-stale posts' },
])
await act(async () => { await act(async () => {
// Click the link to /static-short-stale/124 — a different param than // Click the link to /static-short-stale/124 — a different param than
...@@ -484,23 +477,18 @@ describe('App Shell prefetching', () => { ...@@ -484,23 +477,18 @@ describe('App Shell prefetching', () => {
}) })
const act = createRouterAct(page, { includeAppShellRequests: true }) const act = createRouterAct(page, { includeAppShellRequests: true })
// Reveal the LinkAccordion for /with-root-param/en/static-posts/1. Two prefetch responses // Reveal the LinkAccordion for /with-root-param/en/static-posts/1. The
// fire: one for the per-segment static prefetch of /with-root-param/en/static-posts/1 // route is fully static and opts into Partial Prefetching, so a single
// (which contains the resolved page content + the shell above the // per-segment static prefetch fires, carrying the resolved page content
// params boundary), and one for the runtime shell prefetch (which the // plus the shell prefix above the params boundary (which the client
// server may return either as a truncated shell or as the full // extracts and caches at the Fallback vary path).
// prerender that the client extracts a shell prefix from). Both
// responses contain the "App shell for static posts" substring.
await act(async () => { await act(async () => {
await browser await browser
.elementByCss( .elementByCss(
'input[data-link-accordion="/with-root-param/en/static-posts/1"]' 'input[data-link-accordion="/with-root-param/en/static-posts/1"]'
) )
.click() .click()
}, [ }, [{ includes: 'App shell for static posts with root param: en' }])
{ includes: 'App shell for static posts with root param: en' },
{ includes: 'App shell for static posts with root param: en' },
])
// Click the link to /with-root-param/en/static-posts/124 — a different param than what // Click the link to /with-root-param/en/static-posts/124 — a different param than what
// was prefetched, rendered with prefetch={false}. The cached App // was prefetched, rendered with prefetch={false}. The cached App
...@@ -743,23 +731,18 @@ describe('App Shell prefetching', () => { ...@@ -743,23 +731,18 @@ describe('App Shell prefetching', () => {
}) })
const act = createRouterAct(page, { includeAppShellRequests: true }) const act = createRouterAct(page, { includeAppShellRequests: true })
// Reveal the LinkAccordion for /with-root-param/en/static-posts/1. Two prefetch responses // Reveal the LinkAccordion for /with-root-param/en/static-posts/1. The
// fire: one for the per-segment static prefetch of /with-root-param/en/static-posts/1 // route is fully static and opts into Partial Prefetching, so a single
// (which contains the resolved page content + the shell above the // per-segment static prefetch fires, carrying the resolved page content
// params boundary), and one for the runtime shell prefetch (which the // plus the shell prefix above the params boundary (which the client
// server may return either as a truncated shell or as the full // extracts and caches at the Fallback vary path).
// prerender that the client extracts a shell prefix from). Both
// responses contain the "App shell for static posts" substring.
await act(async () => { await act(async () => {
await browser await browser
.elementByCss( .elementByCss(
'input[data-link-accordion="/with-root-param/en/static-posts/1"]' 'input[data-link-accordion="/with-root-param/en/static-posts/1"]'
) )
.click() .click()
}, [ }, [{ includes: 'App shell for static posts with root param: en' }])
{ includes: 'App shell for static posts with root param: en' },
{ includes: 'App shell for static posts with root param: en' },
])
await act(async () => { await act(async () => {
const startingUrl = await browser.url() const startingUrl = await browser.url()
......
...@@ -3,9 +3,6 @@ import type { NextConfig } from 'next' ...@@ -3,9 +3,6 @@ import type { NextConfig } from 'next'
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { experimental: {
// `appShells` gates the prefetch-serves-fallback-shell behavior that this
// suite exercises. It requires the following flags to also be enabled.
appShells: true,
prefetchInlining: true, prefetchInlining: true,
varyParams: true, varyParams: true,
optimisticRouting: true, optimisticRouting: true,
......
...@@ -8,29 +8,47 @@ export default async function Page() { ...@@ -8,29 +8,47 @@ export default async function Page() {
<h2>thrown errors</h2> <h2>thrown errors</h2>
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/errors/error-after-cookies" /> <DebugLinkAccordion href="/errors/error-after-cookies" prefetch />
</li> </li>
</ul> </ul>
<h2>sync IO</h2> <h2>sync IO</h2>
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/cookies" /> <DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/cookies"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/headers" /> <DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/headers"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/dynamic-params/123" /> <DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/dynamic-params/123"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/search-params?foo=bar" /> <DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/search-params?foo=bar"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/private-cache" /> <DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/private-cache"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/quickly-expiring-public-cache" /> <DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/quickly-expiring-public-cache"
prefetch
/>
</li> </li>
</ul> </ul>
</main> </main>
......
...@@ -11,7 +11,7 @@ export default async function Page() { ...@@ -11,7 +11,7 @@ export default async function Page() {
cookies + dynamic content cookies + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-page/cookies" /> <DebugLinkAccordion href="/in-page/cookies" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -20,7 +20,7 @@ export default async function Page() { ...@@ -20,7 +20,7 @@ export default async function Page() {
headers + dynamic content headers + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-page/headers" /> <DebugLinkAccordion href="/in-page/headers" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -29,10 +29,16 @@ export default async function Page() { ...@@ -29,10 +29,16 @@ export default async function Page() {
search params + dynamic content search params + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-page/search-params?searchParam=123" /> <DebugLinkAccordion
href="/in-page/search-params?searchParam=123"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/in-page/search-params?searchParam=456" /> <DebugLinkAccordion
href="/in-page/search-params?searchParam=456"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -40,10 +46,10 @@ export default async function Page() { ...@@ -40,10 +46,10 @@ export default async function Page() {
dynamic params + dynamic content dynamic params + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-page/dynamic-params/123" /> <DebugLinkAccordion href="/in-page/dynamic-params/123" prefetch />
</li> </li>
<li> <li>
<DebugLinkAccordion href="/in-page/dynamic-params/456" /> <DebugLinkAccordion href="/in-page/dynamic-params/456" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -51,7 +57,7 @@ export default async function Page() { ...@@ -51,7 +57,7 @@ export default async function Page() {
only cookies only cookies
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-page/cookies-only" /> <DebugLinkAccordion href="/in-page/cookies-only" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -65,7 +71,7 @@ export default async function Page() { ...@@ -65,7 +71,7 @@ export default async function Page() {
cookies in private cache + dynamic content cookies in private cache + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-private-cache/cookies" /> <DebugLinkAccordion href="/in-private-cache/cookies" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -73,7 +79,7 @@ export default async function Page() { ...@@ -73,7 +79,7 @@ export default async function Page() {
headers in private cache + dynamic content headers in private cache + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-private-cache/headers" /> <DebugLinkAccordion href="/in-private-cache/headers" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -81,10 +87,16 @@ export default async function Page() { ...@@ -81,10 +87,16 @@ export default async function Page() {
dynamic params in private cache + dynamic content dynamic params in private cache + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-private-cache/dynamic-params/123" /> <DebugLinkAccordion
href="/in-private-cache/dynamic-params/123"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/in-private-cache/dynamic-params/456" /> <DebugLinkAccordion
href="/in-private-cache/dynamic-params/456"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -92,10 +104,16 @@ export default async function Page() { ...@@ -92,10 +104,16 @@ export default async function Page() {
search params in private cache + dynamic content search params in private cache + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-private-cache/search-params?searchParam=123" /> <DebugLinkAccordion
href="/in-private-cache/search-params?searchParam=123"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/in-private-cache/search-params?searchParam=456" /> <DebugLinkAccordion
href="/in-private-cache/search-params?searchParam=456"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -103,7 +121,10 @@ export default async function Page() { ...@@ -103,7 +121,10 @@ export default async function Page() {
only cookies in private cache only cookies in private cache
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-private-cache/cookies-only" /> <DebugLinkAccordion
href="/in-private-cache/cookies-only"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -111,7 +132,7 @@ export default async function Page() { ...@@ -111,7 +132,7 @@ export default async function Page() {
Date.now() in private cache Date.now() in private cache
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/in-private-cache/date-now" /> <DebugLinkAccordion href="/in-private-cache/date-now" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -125,7 +146,10 @@ export default async function Page() { ...@@ -125,7 +146,10 @@ export default async function Page() {
cookies() promise passed to public cache + dynamic content cookies() promise passed to public cache + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/passed-to-public-cache/cookies" /> <DebugLinkAccordion
href="/passed-to-public-cache/cookies"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -133,7 +157,10 @@ export default async function Page() { ...@@ -133,7 +157,10 @@ export default async function Page() {
headers() promise passed to public cache + dynamic content headers() promise passed to public cache + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/passed-to-public-cache/headers" /> <DebugLinkAccordion
href="/passed-to-public-cache/headers"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -141,10 +168,16 @@ export default async function Page() { ...@@ -141,10 +168,16 @@ export default async function Page() {
dynamic params promise passed to public cache + dynamic content dynamic params promise passed to public cache + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/passed-to-public-cache/dynamic-params/123" /> <DebugLinkAccordion
href="/passed-to-public-cache/dynamic-params/123"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/passed-to-public-cache/dynamic-params/456" /> <DebugLinkAccordion
href="/passed-to-public-cache/dynamic-params/456"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -152,10 +185,16 @@ export default async function Page() { ...@@ -152,10 +185,16 @@ export default async function Page() {
search params promise passed to public cache + dynamic content search params promise passed to public cache + dynamic content
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/passed-to-public-cache/search-params?searchParam=123" /> <DebugLinkAccordion
href="/passed-to-public-cache/search-params?searchParam=123"
prefetch
/>
</li> </li>
<li> <li>
<DebugLinkAccordion href="/passed-to-public-cache/search-params?searchParam=456" /> <DebugLinkAccordion
href="/passed-to-public-cache/search-params?searchParam=456"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -163,7 +202,10 @@ export default async function Page() { ...@@ -163,7 +202,10 @@ export default async function Page() {
only cookies passed to public cache (no dynamic content) only cookies passed to public cache (no dynamic content)
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/passed-to-public-cache/cookies-only" /> <DebugLinkAccordion
href="/passed-to-public-cache/cookies-only"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -175,7 +217,7 @@ export default async function Page() { ...@@ -175,7 +217,7 @@ export default async function Page() {
private, short stale private, short stale
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/caches/private-short-stale" /> <DebugLinkAccordion href="/caches/private-short-stale" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -183,7 +225,10 @@ export default async function Page() { ...@@ -183,7 +225,10 @@ export default async function Page() {
public, short expire, long enough stale public, short expire, long enough stale
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/caches/public-short-expire-long-stale" /> <DebugLinkAccordion
href="/caches/public-short-expire-long-stale"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -191,7 +236,10 @@ export default async function Page() { ...@@ -191,7 +236,10 @@ export default async function Page() {
public, short expire, short stale public, short expire, short stale
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/caches/public-short-expire-short-stale" /> <DebugLinkAccordion
href="/caches/public-short-expire-short-stale"
prefetch
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -199,7 +247,7 @@ export default async function Page() { ...@@ -199,7 +247,7 @@ export default async function Page() {
public, cacheLife("seconds") public, cacheLife("seconds")
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/caches/public-seconds" /> <DebugLinkAccordion href="/caches/public-seconds" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -207,7 +255,7 @@ export default async function Page() { ...@@ -207,7 +255,7 @@ export default async function Page() {
private, cacheLife("seconds") private, cacheLife("seconds")
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/caches/private-seconds" /> <DebugLinkAccordion href="/caches/private-seconds" prefetch />
</li> </li>
</ul> </ul>
</li> </li>
...@@ -216,7 +264,7 @@ export default async function Page() { ...@@ -216,7 +264,7 @@ export default async function Page() {
<h2>misc</h2> <h2>misc</h2>
<ul> <ul>
<li> <li>
<DebugLinkAccordion href="/fully-static" /> <DebugLinkAccordion href="/fully-static" prefetch />
</li> </li>
</ul> </ul>
</main> </main>
......
...@@ -16,11 +16,13 @@ export default async function Page() { ...@@ -16,11 +16,13 @@ export default async function Page() {
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion
href={`/with-root-param/${currentLang}/in-page/root-params`} href={`/with-root-param/${currentLang}/in-page/root-params`}
prefetch
/> />
</li> </li>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion
href={`/with-root-param/${otherLang}/in-page/root-params`} href={`/with-root-param/${otherLang}/in-page/root-params`}
prefetch
/> />
</li> </li>
</ul> </ul>
...@@ -37,11 +39,13 @@ export default async function Page() { ...@@ -37,11 +39,13 @@ export default async function Page() {
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion
href={`/with-root-param/${currentLang}/in-private-cache/root-params`} href={`/with-root-param/${currentLang}/in-private-cache/root-params`}
prefetch
/> />
</li> </li>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion
href={`/with-root-param/${otherLang}/in-private-cache/root-params`} href={`/with-root-param/${otherLang}/in-private-cache/root-params`}
prefetch
/> />
</li> </li>
</ul> </ul>
...@@ -58,11 +62,13 @@ export default async function Page() { ...@@ -58,11 +62,13 @@ export default async function Page() {
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion
href={`/with-root-param/${currentLang}/passed-to-public-cache/root-params`} href={`/with-root-param/${currentLang}/passed-to-public-cache/root-params`}
prefetch
/> />
</li> </li>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion
href={`/with-root-param/${otherLang}/passed-to-public-cache/root-params`} href={`/with-root-param/${otherLang}/passed-to-public-cache/root-params`}
prefetch
/> />
</li> </li>
</ul> </ul>
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
const nextConfig = { const nextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { experimental: {
// TODO(appShells): migrate this test to the two-phase (app shell +
// per-page data) prefetch behavior, then remove this override. See #94516.
appShells: false,
// TODO: This test asserts on the pre-`optimisticRouting` prefetch and // TODO: This test asserts on the pre-`optimisticRouting` prefetch and
// search-param-rewrite behavior. Pin the fixture to the old default // search-param-rewrite behavior. Pin the fixture to the old default
// until the test is updated (or until the flag is removed). // until the test is updated (or until the flag is removed).
......
...@@ -21,12 +21,12 @@ export default function Page() { ...@@ -21,12 +21,12 @@ export default function Page() {
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-stale-2-minutes"> <LinkAccordion href="/runtime-stale-2-minutes" prefetch>
Page whose runtime prefetch has a stale time of 2 minutes Page whose runtime prefetch has a stale time of 2 minutes
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-stale-4-minutes"> <LinkAccordion href="/runtime-stale-4-minutes" prefetch>
Page whose runtime prefetch has a stale time of 4 minutes Page whose runtime prefetch has a stale time of 4 minutes
</LinkAccordion> </LinkAccordion>
</li> </li>
......
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
const nextConfig = { const nextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { experimental: {
// The "runtime prefetch" stale-time test relies on a runtime prefetch
// firing when a link is revealed. App Shells defers a non-eager route's
// dynamic content to navigation rather than prefetching it speculatively,
// so keep App Shells off here to exercise runtime-prefetch staleness.
appShells: false,
staleTimes: { staleTimes: {
dynamic: 30, dynamic: 30,
}, },
......
...@@ -6,17 +6,26 @@ export default function RuntimePrefetchAllVaryIndexPage() { ...@@ -6,17 +6,26 @@ export default function RuntimePrefetchAllVaryIndexPage() {
<h1>Runtime Prefetch - All Params in Static Portion</h1> <h1>Runtime Prefetch - All Params in Static Portion</h1>
<ul> <ul>
<li> <li>
<LinkAccordion href="/runtime-prefetch-all-vary/electronics/phone"> <LinkAccordion
href="/runtime-prefetch-all-vary/electronics/phone"
prefetch
>
Electronics: Phone Electronics: Phone
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-all-vary/electronics/tablet"> <LinkAccordion
href="/runtime-prefetch-all-vary/electronics/tablet"
prefetch
>
Electronics: Tablet Electronics: Tablet
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-all-vary/clothing/shirt"> <LinkAccordion
href="/runtime-prefetch-all-vary/clothing/shirt"
prefetch
>
Clothing: Shirt Clothing: Shirt
</LinkAccordion> </LinkAccordion>
</li> </li>
......
...@@ -6,17 +6,26 @@ export default function RuntimePrefetchLayoutSplitIndexPage() { ...@@ -6,17 +6,26 @@ export default function RuntimePrefetchLayoutSplitIndexPage() {
<h1>Runtime Prefetch - Layout/Page Param Split</h1> <h1>Runtime Prefetch - Layout/Page Param Split</h1>
<ul> <ul>
<li> <li>
<LinkAccordion href="/runtime-prefetch-layout-split/electronics/phone"> <LinkAccordion
href="/runtime-prefetch-layout-split/electronics/phone"
prefetch
>
Electronics: Phone Electronics: Phone
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-layout-split/electronics/tablet"> <LinkAccordion
href="/runtime-prefetch-layout-split/electronics/tablet"
prefetch
>
Electronics: Tablet Electronics: Tablet
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-layout-split/clothing/shirt"> <LinkAccordion
href="/runtime-prefetch-layout-split/clothing/shirt"
prefetch
>
Clothing: Shirt Clothing: Shirt
</LinkAccordion> </LinkAccordion>
</li> </li>
......
...@@ -6,12 +6,12 @@ export default function RuntimePrefetchMetadataIndexPage() { ...@@ -6,12 +6,12 @@ export default function RuntimePrefetchMetadataIndexPage() {
<h1>Runtime Prefetch - Metadata Param Access</h1> <h1>Runtime Prefetch - Metadata Param Access</h1>
<ul> <ul>
<li> <li>
<LinkAccordion href="/runtime-prefetch-metadata/aaa"> <LinkAccordion href="/runtime-prefetch-metadata/aaa" prefetch>
Slug: aaa Slug: aaa
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-metadata/bbb"> <LinkAccordion href="/runtime-prefetch-metadata/bbb" prefetch>
Slug: bbb Slug: bbb
</LinkAccordion> </LinkAccordion>
</li> </li>
......
...@@ -6,17 +6,26 @@ export default function RuntimePrefetchNoVaryIndexPage() { ...@@ -6,17 +6,26 @@ export default function RuntimePrefetchNoVaryIndexPage() {
<h1>Runtime Prefetch - No Params in Static Portion</h1> <h1>Runtime Prefetch - No Params in Static Portion</h1>
<ul> <ul>
<li> <li>
<LinkAccordion href="/runtime-prefetch-no-vary/electronics/phone"> <LinkAccordion
href="/runtime-prefetch-no-vary/electronics/phone"
prefetch
>
Electronics: Phone Electronics: Phone
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-no-vary/electronics/tablet"> <LinkAccordion
href="/runtime-prefetch-no-vary/electronics/tablet"
prefetch
>
Electronics: Tablet Electronics: Tablet
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-no-vary/clothing/shirt"> <LinkAccordion
href="/runtime-prefetch-no-vary/clothing/shirt"
prefetch
>
Clothing: Shirt Clothing: Shirt
</LinkAccordion> </LinkAccordion>
</li> </li>
......
...@@ -6,17 +6,26 @@ export default function RuntimePrefetchSearchParamsIndexPage() { ...@@ -6,17 +6,26 @@ export default function RuntimePrefetchSearchParamsIndexPage() {
<h1>Runtime Prefetch - SearchParams Not Accessed</h1> <h1>Runtime Prefetch - SearchParams Not Accessed</h1>
<ul> <ul>
<li> <li>
<LinkAccordion href="/runtime-prefetch-search-params/target-page?q=1"> <LinkAccordion
href="/runtime-prefetch-search-params/target-page?q=1"
prefetch
>
Target q=1 Target q=1
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-search-params/target-page?q=2"> <LinkAccordion
href="/runtime-prefetch-search-params/target-page?q=2"
prefetch
>
Target q=2 Target q=2
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch-search-params/target-page?q=3"> <LinkAccordion
href="/runtime-prefetch-search-params/target-page?q=3"
prefetch
>
Target q=3 Target q=3
</LinkAccordion> </LinkAccordion>
</li> </li>
......
...@@ -30,27 +30,30 @@ export default function RuntimePrefetchIndexPage() { ...@@ -30,27 +30,30 @@ export default function RuntimePrefetchIndexPage() {
</p> </p>
<ul> <ul>
<li> <li>
<LinkAccordion href="/runtime-prefetch/electronics/phone"> <LinkAccordion href="/runtime-prefetch/electronics/phone" prefetch>
Electronics: Phone Electronics: Phone
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch/electronics/tablet"> <LinkAccordion href="/runtime-prefetch/electronics/tablet" prefetch>
Electronics: Tablet Electronics: Tablet
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch/electronics/laptop"> <LinkAccordion href="/runtime-prefetch/electronics/laptop" prefetch>
Electronics: Laptop Electronics: Laptop
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch/electronics/headphones"> <LinkAccordion
href="/runtime-prefetch/electronics/headphones"
prefetch
>
Electronics: Headphones Electronics: Headphones
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/runtime-prefetch/clothing/shirt"> <LinkAccordion href="/runtime-prefetch/clothing/shirt" prefetch>
Clothing: Shirt Clothing: Shirt
</LinkAccordion> </LinkAccordion>
</li> </li>
......
...@@ -28,22 +28,22 @@ export default function SearchParamsIndexPage() { ...@@ -28,22 +28,22 @@ export default function SearchParamsIndexPage() {
<h2>Target (accesses searchParams)</h2> <h2>Target (accesses searchParams)</h2>
<ul> <ul>
<li> <li>
<LinkAccordion href="/search-params/target-page"> <LinkAccordion href="/search-params/target-page" prefetch>
Target with no search params Target with no search params
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/search-params/target-page?foo=1"> <LinkAccordion href="/search-params/target-page?foo=1" prefetch>
Target with foo=1 Target with foo=1
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/search-params/target-page?foo=2"> <LinkAccordion href="/search-params/target-page?foo=2" prefetch>
Target with foo=2 Target with foo=2
</LinkAccordion> </LinkAccordion>
</li> </li>
<li> <li>
<LinkAccordion href="/search-params/target-page?foo=3"> <LinkAccordion href="/search-params/target-page?foo=3" prefetch>
Target with foo=3 Target with foo=3
</LinkAccordion> </LinkAccordion>
</li> </li>
......
...@@ -4,12 +4,6 @@ ...@@ -4,12 +4,6 @@
const nextConfig = { const nextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { experimental: {
// These tests assert on per-link/runtime prefetch responses to verify
// varyParams cache-key behavior. App Shells skips the per-link Speculative
// prefetch for non-eager routes (deferring param-dependent content to
// navigation), which makes that behavior unobservable via prefetch. Keep
// App Shells off here so the varyParams feature is exercised in isolation.
appShells: false,
optimisticRouting: true, optimisticRouting: true,
prefetchInlining: false, prefetchInlining: false,
varyParams: true, varyParams: true,
......
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
// TODO(appShells): migrate this test to the two-phase (app shell +
// per-page data) prefetch behavior, then remove this override. See #94516.
appShells: false,
prefetchInlining: false, prefetchInlining: false,
useCache: true, useCache: true,
}, },
......
...@@ -3,6 +3,11 @@ import { Suspense, cacheSignal } from 'react' ...@@ -3,6 +3,11 @@ import { Suspense, cacheSignal } from 'react'
import { setTimeout } from 'timers/promises' import { setTimeout } from 'timers/promises'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
// `allow-runtime` opts the route into Partial Prefetching (the two-phase Shell
// then Speculative flow) and marks it as needing a runtime request pass. A full
// prefetch (the Link below uses prefetch={true}) resolves the params-dependent
// content via a per-request runtime prefetch (PPRRuntime), which is what
// exercises the non-deterministic cache args during a runtime prefetch.
export const prefetch = 'allow-runtime' export const prefetch = 'allow-runtime'
const callCounts = new Map<string, number>() const callCounts = new Map<string, number>()
...@@ -67,7 +72,14 @@ export default async function Page({ ...@@ -67,7 +72,14 @@ export default async function Page({
const { slug } = await params const { slug } = await params
if (slug === 'with-runtime-prefetch') { if (slug === 'with-runtime-prefetch') {
return <Link href="/known">Go to runtime-prefetchable page</Link> // Use a full prefetch so the per-request runtime prefetch (PPRRuntime)
// fires during the Speculative phase. An auto prefetch of an allow-runtime
// route only warms the reusable shell (RuntimeShell) instead.
return (
<Link href="/known" prefetch={true}>
Go to runtime-prefetchable page
</Link>
)
} }
return ( return (
......
import type { NextConfig } from 'next' import type { NextConfig } from 'next'
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
experimental: {
// TODO(appShells): migrate this test to the two-phase (app shell +
// per-page data) prefetch behavior, then remove this override. See #94516.
appShells: false,
},
cacheComponents: true, cacheComponents: true,
} }
......
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