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({
serverSourceMaps: false,
linkNoTouchStart: false,
caseSensitiveRoutes: false,
clientSegmentCache:
// 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'
),
clientSegmentCache: false,
dynamicOnHover: false,
appDocumentPreloading: undefined,
preloadEntriesOnStart: true,
......@@ -1449,15 +1437,7 @@ export const defaultConfig = Object.freeze({
clientTraceMetadata: undefined,
parallelServerCompiles: false,
parallelServerBuildTraces: false,
ppr:
// 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'
),
ppr: false,
authInterrupts: false,
webpackBuildWorker: undefined,
webpackMemoryOptimizations: false,
......@@ -1478,15 +1458,7 @@ export const defaultConfig = Object.freeze({
serverComponentsHmrCache: true,
staticGenerationMaxConcurrency: 8,
staticGenerationMinPagesPerWorker: 25,
dynamicIO:
// 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'
),
dynamicIO: false,
inlineCss: false,
useCache: undefined,
slowModuleDetection: undefined,
......
......@@ -240,21 +240,6 @@ function assignDefaults(
{}
) 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 = {
...defaultConfig,
...config,
......@@ -1416,6 +1401,7 @@ export default async function loadConfig(
}
enforceExperimentalFeatures(userConfig, {
isDefaultConfig: false,
configuredExperimentalFeatures: reportExperimentalFeatures
? configuredExperimentalFeatures
: undefined,
......@@ -1464,6 +1450,7 @@ export default async function loadConfig(
const clonedDefaultConfig = cloneObject(defaultConfig) as NextConfig
enforceExperimentalFeatures(clonedDefaultConfig, {
isDefaultConfig: true,
configuredExperimentalFeatures: reportExperimentalFeatures
? configuredExperimentalFeatures
: undefined,
......@@ -1497,29 +1484,18 @@ export type ConfiguredExperimentalFeature = {
function enforceExperimentalFeatures(
config: NextConfig,
options: {
isDefaultConfig: boolean
configuredExperimentalFeatures: ConfiguredExperimentalFeature[] | undefined
debugPrerender: boolean | undefined
phase: string
}
) {
const { configuredExperimentalFeatures, debugPrerender, phase } = options
if (
config.experimental &&
config.experimental.enablePrerenderSourceMaps === undefined &&
config.experimental.dynamicIO === true
) {
config.experimental.enablePrerenderSourceMaps = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'enablePrerenderSourceMaps',
true,
'enabled by `experimental.dynamicIO`'
)
}
}
const {
configuredExperimentalFeatures,
debugPrerender,
isDefaultConfig,
phase,
} = options
config.experimental ??= {}
......@@ -1555,6 +1531,98 @@ function enforceExperimentalFeatures(
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<
......
......@@ -250,6 +250,7 @@
"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/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/incremental-opt-in/segment-cache-incremental-opt-in.test.ts",
"test/e2e/app-dir/segment-cache/memory-pressure/segment-cache-memory-pressure.test.ts",
......@@ -333,7 +334,6 @@
"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/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/index.test.ts",
"test/production/app-dir/client-components-tree-shaking/index.test.ts",
......
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
ppr: process.env.__NEXT_EXPERIMENTAL_PPR === 'true',
},
}
const nextConfig = {}
module.exports = nextConfig
......@@ -5,7 +5,6 @@ const nextConfig = {
experimental: {
useCache: true,
prerenderEarlyExit: false,
ppr: process.env.__NEXT_EXPERIMENTAL_PPR === 'true',
},
}
......
......@@ -3,7 +3,6 @@
*/
const nextConfig = {
experimental: {
ppr: process.env.__NEXT_EXPERIMENTAL_PPR === 'true',
useCache: true,
cacheLife: {
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