From 2b5d8970bd6b16bfc1d8c63ea7577619fa4c1467 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 12 Nov 2024 14:45:51 -0500 Subject: [PATCH] Add experimental `clientSegmentCache` flag (#72626) This will be used to gate a rewrite of the client cache that we've just started. Eventually it should merge with the PPR rollout, but that's already in active experimentation and we don't want to harm the PPR rollout. This will also let us incrementally get to parity with the existing implementation, instead of trying to reach parity in one big step. When enabled (and when a route is using PPR), prefetches will use a new per-segment cache instead of the existing per-page cache. --- packages/next/src/build/webpack/plugins/define-env-plugin.ts | 3 +++ packages/next/src/server/config-schema.ts | 1 + packages/next/src/server/config-shared.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/packages/next/src/build/webpack/plugins/define-env-plugin.ts b/packages/next/src/build/webpack/plugins/define-env-plugin.ts index 7146be5500dfd..90a5be891a0c5 100644 --- a/packages/next/src/build/webpack/plugins/define-env-plugin.ts +++ b/packages/next/src/build/webpack/plugins/define-env-plugin.ts @@ -217,6 +217,9 @@ export function getDefineEnv({ clientRouterFilters?.staticFilter ?? false, 'process.env.__NEXT_CLIENT_ROUTER_D_FILTER': clientRouterFilters?.dynamicFilter ?? false, + 'process.env.__NEXT_CLIENT_SEGMENT_CACHE': Boolean( + config.experimental.clientSegmentCache + ), 'process.env.__NEXT_OPTIMISTIC_CLIENT_CACHE': config.experimental.optimisticClientCache ?? true, 'process.env.__NEXT_MIDDLEWARE_PREFETCH': diff --git a/packages/next/src/server/config-schema.ts b/packages/next/src/server/config-schema.ts index cd65de10d5afd..10e32cef697af 100644 --- a/packages/next/src/server/config-schema.ts +++ b/packages/next/src/server/config-schema.ts @@ -288,6 +288,7 @@ export const configSchema: zod.ZodType = z.lazy(() => memoryBasedWorkersCount: z.boolean().optional(), craCompat: z.boolean().optional(), caseSensitiveRoutes: z.boolean().optional(), + clientSegmentCache: z.boolean().optional(), disableOptimizedLoading: z.boolean().optional(), disablePostcssPresetEnv: z.boolean().optional(), dynamicIO: z.boolean().optional(), diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index a1bd9a74eadf1..7ededa08b235b 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -249,6 +249,7 @@ export interface ExperimentalConfig { prerenderEarlyExit?: boolean linkNoTouchStart?: boolean caseSensitiveRoutes?: boolean + clientSegmentCache?: boolean appDocumentPreloading?: boolean preloadEntriesOnStart?: boolean /** @default true */ @@ -1085,6 +1086,7 @@ export const defaultConfig: NextConfig = { serverSourceMaps: false, linkNoTouchStart: false, caseSensitiveRoutes: false, + clientSegmentCache: false, appDocumentPreloading: undefined, preloadEntriesOnStart: true, clientRouterFilter: true,