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

Add experimental.varyParams feature flag (#89307)

## Summary

- Adds `experimental.varyParams` feature flag (defaults to `false`)
- When disabled, the client skips vary params rekeying and treats params
as unknown
- Allows internal rollout with easy revert if regressions occur during
dogfooding

The flag only gates the client-side rekeying logic in `cache.ts`.
Server-side param tracking continues regardless.

## Test plan

- Enabled the flag in the vary-params and optimistic-routing test
fixtures
parent 99eae38f
...@@ -359,6 +359,7 @@ export function getDefineEnv({ ...@@ -359,6 +359,7 @@ export function getDefineEnv({
config.experimental.gestureTransition ?? false, config.experimental.gestureTransition ?? false,
'process.env.__NEXT_OPTIMISTIC_ROUTING': 'process.env.__NEXT_OPTIMISTIC_ROUTING':
config.experimental.optimisticRouting ?? false, config.experimental.optimisticRouting ?? false,
'process.env.__NEXT_VARY_PARAMS': config.experimental.varyParams ?? false,
'process.env.__NEXT_CACHE_LIFE': config.cacheLife, 'process.env.__NEXT_CACHE_LIFE': config.cacheLife,
'process.env.__NEXT_CLIENT_PARAM_PARSING_ORIGINS': 'process.env.__NEXT_CLIENT_PARAM_PARSING_ORIGINS':
config.experimental.clientParamParsingOrigins || [], config.experimental.clientParamParsingOrigins || [],
......
...@@ -1924,7 +1924,7 @@ export async function fetchSegmentOnCacheMiss( ...@@ -1924,7 +1924,7 @@ export async function fetchSegmentOnCacheMiss(
// across different param values for params that the segment doesn't // across different param values for params that the segment doesn't
// actually depend on. // actually depend on.
const varyParams = serverData.varyParams const varyParams = serverData.varyParams
if (varyParams !== null) { if (process.env.__NEXT_VARY_PARAMS && varyParams !== null) {
// Re-key the entry by storing it at a more generic vary path where // Re-key the entry by storing it at a more generic vary path where
// unused params are replaced with Fallback. // unused params are replaced with Fallback.
const fulfilledVaryPath = getFulfilledSegmentVaryPath( const fulfilledVaryPath = getFulfilledSegmentVaryPath(
...@@ -2407,7 +2407,7 @@ function fulfillEntrySpawnedByRuntimePrefetch( ...@@ -2407,7 +2407,7 @@ function fulfillEntrySpawnedByRuntimePrefetch(
isPartial isPartial
) )
// Re-key the entry based on which params the segment actually depends on. // Re-key the entry based on which params the segment actually depends on.
if (segmentVaryParams !== null) { if (process.env.__NEXT_VARY_PARAMS && segmentVaryParams !== null) {
const fulfilledVaryPath = getFulfilledSegmentVaryPath( const fulfilledVaryPath = getFulfilledSegmentVaryPath(
tree.varyPath, tree.varyPath,
segmentVaryParams segmentVaryParams
...@@ -2437,7 +2437,7 @@ function fulfillEntrySpawnedByRuntimePrefetch( ...@@ -2437,7 +2437,7 @@ function fulfillEntrySpawnedByRuntimePrefetch(
isPartial isPartial
) )
// Re-key the entry based on which params the segment actually depends on. // Re-key the entry based on which params the segment actually depends on.
if (segmentVaryParams !== null) { if (process.env.__NEXT_VARY_PARAMS && segmentVaryParams !== null) {
const fulfilledVaryPath = getFulfilledSegmentVaryPath( const fulfilledVaryPath = getFulfilledSegmentVaryPath(
tree.varyPath, tree.varyPath,
segmentVaryParams segmentVaryParams
...@@ -2465,7 +2465,7 @@ function fulfillEntrySpawnedByRuntimePrefetch( ...@@ -2465,7 +2465,7 @@ function fulfillEntrySpawnedByRuntimePrefetch(
// Use the fulfilled vary path if available, otherwise fall back to // Use the fulfilled vary path if available, otherwise fall back to
// the request vary path. // the request vary path.
const varyPath = const varyPath =
segmentVaryParams !== null process.env.__NEXT_VARY_PARAMS && segmentVaryParams !== null
? getFulfilledSegmentVaryPath(tree.varyPath, segmentVaryParams) ? getFulfilledSegmentVaryPath(tree.varyPath, segmentVaryParams)
: getSegmentVaryPathForRequest(fetchStrategy, tree) : getSegmentVaryPathForRequest(fetchStrategy, tree)
upsertSegmentEntry(now, varyPath, newEntry) upsertSegmentEntry(now, varyPath, newEntry)
......
...@@ -210,6 +210,7 @@ export const experimentalSchema = { ...@@ -210,6 +210,7 @@ export const experimentalSchema = {
clientParamParsingOrigins: z.array(z.string()).optional(), clientParamParsingOrigins: z.array(z.string()).optional(),
dynamicOnHover: z.boolean().optional(), dynamicOnHover: z.boolean().optional(),
optimisticRouting: z.boolean().optional(), optimisticRouting: z.boolean().optional(),
varyParams: z.boolean().optional(),
disableOptimizedLoading: z.boolean().optional(), disableOptimizedLoading: z.boolean().optional(),
disablePostcssPresetEnv: z.boolean().optional(), disablePostcssPresetEnv: z.boolean().optional(),
cacheComponents: z.boolean().optional(), cacheComponents: z.boolean().optional(),
......
...@@ -333,6 +333,7 @@ export interface ExperimentalConfig { ...@@ -333,6 +333,7 @@ export interface ExperimentalConfig {
clientParamParsingOrigins?: string[] clientParamParsingOrigins?: string[]
dynamicOnHover?: boolean dynamicOnHover?: boolean
optimisticRouting?: boolean optimisticRouting?: boolean
varyParams?: boolean
preloadEntriesOnStart?: boolean preloadEntriesOnStart?: boolean
clientRouterFilter?: boolean clientRouterFilter?: boolean
clientRouterFilterRedirects?: boolean clientRouterFilterRedirects?: boolean
...@@ -1568,6 +1569,7 @@ export const defaultConfig = Object.freeze({ ...@@ -1568,6 +1569,7 @@ export const defaultConfig = Object.freeze({
caseSensitiveRoutes: false, caseSensitiveRoutes: false,
clientParamParsingOrigins: undefined, clientParamParsingOrigins: undefined,
dynamicOnHover: false, dynamicOnHover: false,
varyParams: false,
preloadEntriesOnStart: true, preloadEntriesOnStart: true,
clientRouterFilter: true, clientRouterFilter: true,
clientRouterFilterRedirects: false, clientRouterFilterRedirects: false,
......
...@@ -5,6 +5,7 @@ const nextConfig = { ...@@ -5,6 +5,7 @@ const nextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { experimental: {
optimisticRouting: true, optimisticRouting: true,
varyParams: true,
}, },
productionBrowserSourceMaps: true, productionBrowserSourceMaps: true,
} }
......
...@@ -5,6 +5,7 @@ const nextConfig = { ...@@ -5,6 +5,7 @@ const nextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { experimental: {
optimisticRouting: true, optimisticRouting: true,
varyParams: 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