Unverified Commit d8fdb6ff authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Simplify running test apps locally with `ppr` or `dynamicIO` enabled (#81668)

We want to respect the `__NEXT_EXPERIMENTAL_PPR` and `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS` environment variables in the test apps, so that we can run them locally with these features enabled without needing to modify the config files.

So we're removing the requirement that `__NEXT_TEST_MODE` needs to be set at the same time. Usually you don't want to set this variable locally because it also changes other behavior in a few places.

This really has no downside, because it was already possible for users to set both variables and affect the flags, and now this can be done with a single variable. It allows us to keep the noise out of the test app's next config files.

We're also moving the assignments from the default config into `enforceExperimentalFeatures` to get the nice output when printing the experimental features in the CLI.
parent 386afcd4
...@@ -1392,19 +1392,7 @@ export const defaultConfig = Object.freeze({ ...@@ -1392,19 +1392,7 @@ export const defaultConfig = Object.freeze({
serverSourceMaps: false, serverSourceMaps: false,
linkNoTouchStart: false, linkNoTouchStart: false,
caseSensitiveRoutes: false, caseSensitiveRoutes: false,
clientSegmentCache: clientSegmentCache: false,
// TODO: Remove once we've made clientSegmentCache the default. We're
// piggybacking on the PPR test flag, instead of introducing a separate
// CI run.
//
// If we're testing, and the `__NEXT_EXPERIMENTAL_PPR` environment
// variable has been set to `true`, enable the experimental
// clientSegmentCache feature so long as it wasn't explicitly disabled in
// the config.
!!(
process.env.__NEXT_TEST_MODE &&
process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
),
dynamicOnHover: false, dynamicOnHover: false,
appDocumentPreloading: undefined, appDocumentPreloading: undefined,
preloadEntriesOnStart: true, preloadEntriesOnStart: true,
...@@ -1449,15 +1437,7 @@ export const defaultConfig = Object.freeze({ ...@@ -1449,15 +1437,7 @@ export const defaultConfig = Object.freeze({
clientTraceMetadata: undefined, clientTraceMetadata: undefined,
parallelServerCompiles: false, parallelServerCompiles: false,
parallelServerBuildTraces: false, parallelServerBuildTraces: false,
ppr: ppr: false,
// TODO: remove once we've made PPR default
// If we're testing, and the `__NEXT_EXPERIMENTAL_PPR` environment variable
// has been set to `true`, enable the experimental PPR feature so long as it
// wasn't explicitly disabled in the config.
!!(
process.env.__NEXT_TEST_MODE &&
process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
),
authInterrupts: false, authInterrupts: false,
webpackBuildWorker: undefined, webpackBuildWorker: undefined,
webpackMemoryOptimizations: false, webpackMemoryOptimizations: false,
...@@ -1478,15 +1458,7 @@ export const defaultConfig = Object.freeze({ ...@@ -1478,15 +1458,7 @@ export const defaultConfig = Object.freeze({
serverComponentsHmrCache: true, serverComponentsHmrCache: true,
staticGenerationMaxConcurrency: 8, staticGenerationMaxConcurrency: 8,
staticGenerationMinPagesPerWorker: 25, staticGenerationMinPagesPerWorker: 25,
dynamicIO: dynamicIO: false,
// TODO: remove once we've made dynamicIO the default
// If we're testing, and the `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS` environment
// variable has been set to `true`, enable the experimental dynamicIO feature so long as it
// wasn't explicitly disabled in the config.
!!(
process.env.__NEXT_TEST_MODE &&
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
),
inlineCss: false, inlineCss: false,
useCache: undefined, useCache: undefined,
slowModuleDetection: undefined, slowModuleDetection: undefined,
......
...@@ -240,21 +240,6 @@ function assignDefaults( ...@@ -240,21 +240,6 @@ function assignDefaults(
{} {}
) as NextConfig & { configFileName: string } ) as NextConfig & { configFileName: string }
// TODO: remove these once we've made PPR default
// If this was defaulted to true, it implies that the configuration was
// overridden for testing to be defaulted on.
if (defaultConfig.experimental?.ppr) {
Log.warn(
`\`experimental.ppr\` has been defaulted to \`true\` because \`__NEXT_EXPERIMENTAL_PPR\` was set to \`true\` during testing.`
)
}
if (defaultConfig.experimental?.dynamicIO) {
Log.warn(
`\`experimental.dynamicIO\` has been defaulted to \`true\` because \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\` was set to \`true\` during testing.`
)
}
const result = { const result = {
...defaultConfig, ...defaultConfig,
...config, ...config,
...@@ -1416,6 +1401,7 @@ export default async function loadConfig( ...@@ -1416,6 +1401,7 @@ export default async function loadConfig(
} }
enforceExperimentalFeatures(userConfig, { enforceExperimentalFeatures(userConfig, {
isDefaultConfig: false,
configuredExperimentalFeatures: reportExperimentalFeatures configuredExperimentalFeatures: reportExperimentalFeatures
? configuredExperimentalFeatures ? configuredExperimentalFeatures
: undefined, : undefined,
...@@ -1464,6 +1450,7 @@ export default async function loadConfig( ...@@ -1464,6 +1450,7 @@ export default async function loadConfig(
const clonedDefaultConfig = cloneObject(defaultConfig) as NextConfig const clonedDefaultConfig = cloneObject(defaultConfig) as NextConfig
enforceExperimentalFeatures(clonedDefaultConfig, { enforceExperimentalFeatures(clonedDefaultConfig, {
isDefaultConfig: true,
configuredExperimentalFeatures: reportExperimentalFeatures configuredExperimentalFeatures: reportExperimentalFeatures
? configuredExperimentalFeatures ? configuredExperimentalFeatures
: undefined, : undefined,
...@@ -1497,29 +1484,18 @@ export type ConfiguredExperimentalFeature = { ...@@ -1497,29 +1484,18 @@ export type ConfiguredExperimentalFeature = {
function enforceExperimentalFeatures( function enforceExperimentalFeatures(
config: NextConfig, config: NextConfig,
options: { options: {
isDefaultConfig: boolean
configuredExperimentalFeatures: ConfiguredExperimentalFeature[] | undefined configuredExperimentalFeatures: ConfiguredExperimentalFeature[] | undefined
debugPrerender: boolean | undefined debugPrerender: boolean | undefined
phase: string phase: string
} }
) { ) {
const { configuredExperimentalFeatures, debugPrerender, phase } = options const {
configuredExperimentalFeatures,
if ( debugPrerender,
config.experimental && isDefaultConfig,
config.experimental.enablePrerenderSourceMaps === undefined && phase,
config.experimental.dynamicIO === true } = options
) {
config.experimental.enablePrerenderSourceMaps = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'enablePrerenderSourceMaps',
true,
'enabled by `experimental.dynamicIO`'
)
}
}
config.experimental ??= {} config.experimental ??= {}
...@@ -1555,6 +1531,98 @@ function enforceExperimentalFeatures( ...@@ -1555,6 +1531,98 @@ function enforceExperimentalFeatures(
configuredExperimentalFeatures configuredExperimentalFeatures
) )
} }
// TODO: Remove this once we've made Cache Components the default.
if (
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.ppr === undefined ||
(isDefaultConfig && !config.experimental.ppr))
) {
config.experimental.ppr = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'ppr',
true,
'enabled by `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS`'
)
}
}
// TODO: Remove this once we've made Cache Components the default.
if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.ppr === undefined ||
(isDefaultConfig && !config.experimental.ppr))
) {
config.experimental.ppr = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'ppr',
true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`'
)
}
}
// TODO: Remove this once we've made Client Segment Cache the default.
if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.clientSegmentCache === undefined ||
(isDefaultConfig && !config.experimental.clientSegmentCache))
) {
config.experimental.clientSegmentCache = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'clientSegmentCache',
true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`'
)
}
}
// TODO: Remove this once we've made Cache Components the default.
if (
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.dynamicIO === undefined ||
(isDefaultConfig && !config.experimental.dynamicIO))
) {
config.experimental.dynamicIO = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'dynamicIO',
true,
'enabled by `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS`'
)
}
}
if (
config.experimental.enablePrerenderSourceMaps === undefined &&
config.experimental.dynamicIO === true
) {
config.experimental.enablePrerenderSourceMaps = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'enablePrerenderSourceMaps',
true,
'enabled by `experimental.dynamicIO`'
)
}
}
} }
function addConfiguredExperimentalFeature< function addConfiguredExperimentalFeature<
......
...@@ -250,6 +250,7 @@ ...@@ -250,6 +250,7 @@
"test/e2e/app-dir/segment-cache/basic/segment-cache-basic.test.ts", "test/e2e/app-dir/segment-cache/basic/segment-cache-basic.test.ts",
"test/e2e/app-dir/segment-cache/client-only-opt-in/client-only-opt-in.test.ts", "test/e2e/app-dir/segment-cache/client-only-opt-in/client-only-opt-in.test.ts",
"test/e2e/app-dir/segment-cache/conflicting-routes/conflicting-routes.test.ts", "test/e2e/app-dir/segment-cache/conflicting-routes/conflicting-routes.test.ts",
"test/e2e/app-dir/segment-cache/deployment-skew/deployment-skew.test.ts",
"test/e2e/app-dir/segment-cache/export/segment-cache-output-export.test.ts", "test/e2e/app-dir/segment-cache/export/segment-cache-output-export.test.ts",
"test/e2e/app-dir/segment-cache/incremental-opt-in/segment-cache-incremental-opt-in.test.ts", "test/e2e/app-dir/segment-cache/incremental-opt-in/segment-cache-incremental-opt-in.test.ts",
"test/e2e/app-dir/segment-cache/memory-pressure/segment-cache-memory-pressure.test.ts", "test/e2e/app-dir/segment-cache/memory-pressure/segment-cache-memory-pressure.test.ts",
...@@ -333,7 +334,6 @@ ...@@ -333,7 +334,6 @@
"test/production/app-dir/actions-tree-shaking/reexport/reexport.test.ts", "test/production/app-dir/actions-tree-shaking/reexport/reexport.test.ts",
"test/production/app-dir/actions-tree-shaking/use-effect-actions/use-effect-actions-edge.test.ts", "test/production/app-dir/actions-tree-shaking/use-effect-actions/use-effect-actions-edge.test.ts",
"test/production/app-dir/app-fetch-build-cache/app-fetch-build-cache.test.ts", "test/production/app-dir/app-fetch-build-cache/app-fetch-build-cache.test.ts",
"test/production/app-dir/build-output-prerender/build-output-prerender.test.ts",
"test/production/app-dir/build-output-tree-view/build-output-tree-view.test.ts", "test/production/app-dir/build-output-tree-view/build-output-tree-view.test.ts",
"test/production/app-dir/build-output/index.test.ts", "test/production/app-dir/build-output/index.test.ts",
"test/production/app-dir/client-components-tree-shaking/index.test.ts", "test/production/app-dir/client-components-tree-shaking/index.test.ts",
......
/** /**
* @type {import('next').NextConfig} * @type {import('next').NextConfig}
*/ */
const nextConfig = { const nextConfig = {}
experimental: {
ppr: process.env.__NEXT_EXPERIMENTAL_PPR === 'true',
},
}
module.exports = nextConfig module.exports = nextConfig
...@@ -5,7 +5,6 @@ const nextConfig = { ...@@ -5,7 +5,6 @@ const nextConfig = {
experimental: { experimental: {
useCache: true, useCache: true,
prerenderEarlyExit: false, prerenderEarlyExit: false,
ppr: process.env.__NEXT_EXPERIMENTAL_PPR === 'true',
}, },
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: process.env.__NEXT_EXPERIMENTAL_PPR === 'true',
useCache: true, useCache: true,
cacheLife: { cacheLife: {
frequent: { frequent: {
......
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