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

Indicate boolean value for configured experimental features on startup (#74691)

When printing the configured experimental features of the Next.js config, we are currently not discriminating `true` from `false` values. This is especially confusing when disabling an experimental feature that is enabled by default. In this case it appears in the output as if the feature was enabled.

By using `✓` and `⨯` for boolean feature flags (and `·` for others), users can now clearly see whether a configured feature is enabled or disabled.

**Before:**

<img width="377" alt="before" src="https://github.com/user-attachments/assets/9cb75c1a-910d-48d2-ba1e-048213523e5f" />

**After:**

<img width="377" alt="after" src="https://github.com/user-attachments/assets/9975366d-b8fd-48ef-83e3-44fbad633f48" />
parent cbef6478
...@@ -904,12 +904,15 @@ export default async function build( ...@@ -904,12 +904,15 @@ export default async function build(
) )
// Always log next version first then start rest jobs // Always log next version first then start rest jobs
const { envInfo, expFeatureInfo } = await getStartServerInfo(dir, false) const { envInfo, experimentalFeatures } = await getStartServerInfo(
dir,
false
)
logStartInfo({ logStartInfo({
networkUrl: null, networkUrl: null,
appUrl: null, appUrl: null,
envInfo, envInfo,
expFeatureInfo, experimentalFeatures,
}) })
const ignoreESLint = Boolean(config.eslint.ignoreDuringBuilds) const ignoreESLint = Boolean(config.eslint.ignoreDuringBuilds)
......
...@@ -1268,29 +1268,40 @@ export default async function loadConfig( ...@@ -1268,29 +1268,40 @@ export default async function loadConfig(
return completeConfig return completeConfig
} }
export function getEnabledExperimentalFeatures( export type ConfiguredExperimentalFeature =
| { name: keyof ExperimentalConfig; type: 'boolean'; value: boolean }
| { name: keyof ExperimentalConfig; type: 'other' }
export function getConfiguredExperimentalFeatures(
userNextConfigExperimental: NextConfig['experimental'] userNextConfigExperimental: NextConfig['experimental']
) { ) {
const enabledExperiments: (keyof ExperimentalConfig)[] = [] const configuredExperimentalFeatures: ConfiguredExperimentalFeature[] = []
if (!userNextConfigExperimental) return enabledExperiments if (!userNextConfigExperimental) {
return configuredExperimentalFeatures
}
// defaultConfig.experimental is predefined and will never be undefined // defaultConfig.experimental is predefined and will never be undefined
// This is only a type guard for the typescript // This is only a type guard for the typescript
if (defaultConfig.experimental) { if (defaultConfig.experimental) {
for (const featureName of Object.keys( for (const name of Object.keys(
userNextConfigExperimental userNextConfigExperimental
) as (keyof ExperimentalConfig)[]) { ) as (keyof ExperimentalConfig)[]) {
const value = userNextConfigExperimental[name]
if ( if (
featureName in defaultConfig.experimental && name in defaultConfig.experimental &&
userNextConfigExperimental[featureName] !== value !== defaultConfig.experimental[name]
defaultConfig.experimental[featureName]
) { ) {
enabledExperiments.push(featureName) configuredExperimentalFeatures.push(
typeof value === 'boolean'
? { name, type: 'boolean', value }
: { name, type: 'other' }
)
} }
} }
} }
return enabledExperiments return configuredExperimentalFeatures
} }
class CanaryOnlyError extends Error { class CanaryOnlyError extends Error {
......
...@@ -5,19 +5,22 @@ import { ...@@ -5,19 +5,22 @@ import {
PHASE_DEVELOPMENT_SERVER, PHASE_DEVELOPMENT_SERVER,
PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_BUILD,
} from '../../shared/lib/constants' } from '../../shared/lib/constants'
import loadConfig, { getEnabledExperimentalFeatures } from '../config' import loadConfig, {
getConfiguredExperimentalFeatures,
type ConfiguredExperimentalFeature,
} from '../config'
export function logStartInfo({ export function logStartInfo({
networkUrl, networkUrl,
appUrl, appUrl,
envInfo, envInfo,
expFeatureInfo, experimentalFeatures,
maxExperimentalFeatures = Infinity, maxExperimentalFeatures = Infinity,
}: { }: {
networkUrl: string | null networkUrl: string | null
appUrl: string | null appUrl: string | null
envInfo?: string[] envInfo?: string[]
expFeatureInfo?: string[] experimentalFeatures?: ConfiguredExperimentalFeature[]
maxExperimentalFeatures?: number maxExperimentalFeatures?: number
}) { }) {
Log.bootstrap( Log.bootstrap(
...@@ -33,14 +36,21 @@ export function logStartInfo({ ...@@ -33,14 +36,21 @@ export function logStartInfo({
} }
if (envInfo?.length) Log.bootstrap(`- Environments: ${envInfo.join(', ')}`) if (envInfo?.length) Log.bootstrap(`- Environments: ${envInfo.join(', ')}`)
if (expFeatureInfo?.length) { if (experimentalFeatures?.length) {
Log.bootstrap(`- Experiments (use with caution):`) Log.bootstrap(`- Experiments (use with caution):`)
// only show a maximum number of flags // only show a maximum number of flags
for (const exp of expFeatureInfo.slice(0, maxExperimentalFeatures)) { for (const exp of experimentalFeatures.slice(0, maxExperimentalFeatures)) {
Log.bootstrap(` · ${exp}`) const symbol =
exp.type === 'boolean'
? exp.value === true
? bold('✓')
: bold('⨯')
: '·'
Log.bootstrap(` ${symbol} ${exp.name}`)
} }
/* indicate if there are more than the maximum shown no. flags */ /* indicate if there are more than the maximum shown no. flags */
if (expFeatureInfo.length > maxExperimentalFeatures) { if (experimentalFeatures.length > maxExperimentalFeatures) {
Log.bootstrap(` · ...`) Log.bootstrap(` · ...`)
} }
} }
...@@ -54,19 +64,19 @@ export async function getStartServerInfo( ...@@ -54,19 +64,19 @@ export async function getStartServerInfo(
dev: boolean dev: boolean
): Promise<{ ): Promise<{
envInfo?: string[] envInfo?: string[]
expFeatureInfo?: string[] experimentalFeatures?: ConfiguredExperimentalFeature[]
}> { }> {
let expFeatureInfo: string[] = [] let experimentalFeatures: ConfiguredExperimentalFeature[] = []
await loadConfig( await loadConfig(
dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD, dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD,
dir, dir,
{ {
onLoadUserConfig(userConfig) { onLoadUserConfig(userConfig) {
const userNextConfigExperimental = getEnabledExperimentalFeatures( const configuredExperimentalFeatures =
userConfig.experimental getConfiguredExperimentalFeatures(userConfig.experimental)
)
expFeatureInfo = userNextConfigExperimental.sort( experimentalFeatures = configuredExperimentalFeatures.sort(
(a, b) => a.length - b.length ({ name: a }, { name: b }) => a.length - b.length
) )
}, },
} }
...@@ -83,6 +93,6 @@ export async function getStartServerInfo( ...@@ -83,6 +93,6 @@ export async function getStartServerInfo(
return { return {
envInfo, envInfo,
expFeatureInfo, experimentalFeatures,
} }
} }
...@@ -34,6 +34,7 @@ import { isPostpone } from './router-utils/is-postpone' ...@@ -34,6 +34,7 @@ import { isPostpone } from './router-utils/is-postpone'
import { isIPv6 } from './is-ipv6' import { isIPv6 } from './is-ipv6'
import { AsyncCallbackSet } from './async-callback-set' import { AsyncCallbackSet } from './async-callback-set'
import type { NextServer } from '../next' import type { NextServer } from '../next'
import type { ConfiguredExperimentalFeature } from '../config'
const debug = setupDebug('next:start-server') const debug = setupDebug('next:start-server')
let startServerSpan: Span | undefined let startServerSpan: Span | undefined
...@@ -270,17 +271,17 @@ export async function startServer( ...@@ -270,17 +271,17 @@ export async function startServer(
// Only load env and config in dev to for logging purposes // Only load env and config in dev to for logging purposes
let envInfo: string[] | undefined let envInfo: string[] | undefined
let expFeatureInfo: string[] | undefined let experimentalFeatures: ConfiguredExperimentalFeature[] | undefined
if (isDev) { if (isDev) {
const startServerInfo = await getStartServerInfo(dir, isDev) const startServerInfo = await getStartServerInfo(dir, isDev)
envInfo = startServerInfo.envInfo envInfo = startServerInfo.envInfo
expFeatureInfo = startServerInfo.expFeatureInfo experimentalFeatures = startServerInfo.experimentalFeatures
} }
logStartInfo({ logStartInfo({
networkUrl, networkUrl,
appUrl, appUrl,
envInfo, envInfo,
expFeatureInfo, experimentalFeatures,
maxExperimentalFeatures: 3, maxExperimentalFeatures: 3,
}) })
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry, findAllTelemetryEvents } from 'next-test-utils' import { retry, findAllTelemetryEvents } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
describe('ppr', () => { describe('ppr', () => {
const { next, isNextDev, isNextStart } = nextTestSetup({ const { next, isNextDev, isNextStart } = nextTestSetup({
...@@ -12,7 +13,7 @@ describe('ppr', () => { ...@@ -12,7 +13,7 @@ describe('ppr', () => {
it('should indicate the feature is experimental', async () => { it('should indicate the feature is experimental', async () => {
await retry(() => { await retry(() => {
expect(next.cliOutput).toContain('Experiments (use with caution)') expect(next.cliOutput).toContain('Experiments (use with caution)')
expect(next.cliOutput).toContain('ppr') expect(stripAnsi(next.cliOutput)).toContain('✓ ppr')
}) })
}) })
if (isNextStart) { if (isNextStart) {
......
import { nextTestSetup, FileRef } from 'e2e-utils' import { nextTestSetup, FileRef } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
import stripAnsi from 'strip-ansi'
describe.each( describe.each(
['default', process.env.TURBOPACK ? undefined : 'babelrc'].filter(Boolean) ['default', process.env.TURBOPACK ? undefined : 'babelrc'].filter(Boolean)
...@@ -22,7 +23,7 @@ describe.each( ...@@ -22,7 +23,7 @@ describe.each(
it('should show an experimental warning', async () => { it('should show an experimental warning', async () => {
await retry(() => { await retry(() => {
expect(next.cliOutput).toContain('Experiments (use with caution)') expect(next.cliOutput).toContain('Experiments (use with caution)')
expect(next.cliOutput).toContain('reactCompiler') expect(stripAnsi(next.cliOutput)).toContain('✓ reactCompiler')
}) })
}) })
......
...@@ -84,7 +84,7 @@ describe('Config Experimental Warning', () => { ...@@ -84,7 +84,7 @@ describe('Config Experimental Warning', () => {
const stdout = await collectStdoutFromDev(appDir) const stdout = await collectStdoutFromDev(appDir)
expect(stdout).toMatch(experimentalHeader) expect(stdout).toMatch(experimentalHeader)
expect(stdout).toMatch(' · workerThreads') expect(stdout).toMatch(' ✓ workerThreads')
}) })
it('should show warning with config from function with experimental', async () => { it('should show warning with config from function with experimental', async () => {
...@@ -98,7 +98,7 @@ describe('Config Experimental Warning', () => { ...@@ -98,7 +98,7 @@ describe('Config Experimental Warning', () => {
const stdout = await collectStdoutFromDev(appDir) const stdout = await collectStdoutFromDev(appDir)
expect(stdout).toMatch(experimentalHeader) expect(stdout).toMatch(experimentalHeader)
expect(stdout).toMatch(' · workerThreads') expect(stdout).toMatch(' ✓ workerThreads')
}) })
it('should not show warning with default value', async () => { it('should not show warning with default value', async () => {
...@@ -112,7 +112,21 @@ describe('Config Experimental Warning', () => { ...@@ -112,7 +112,21 @@ describe('Config Experimental Warning', () => {
const stdout = await collectStdoutFromDev(appDir) const stdout = await collectStdoutFromDev(appDir)
expect(stdout).not.toContain(experimentalHeader) expect(stdout).not.toContain(experimentalHeader)
expect(stdout).not.toContain(' · workerThreads') expect(stdout).not.toContain('workerThreads')
})
it('should show warning with a symbol indicating that a default `true` value is set to `false`', async () => {
configFile.write(`
module.exports = {
experimental: {
prerenderEarlyExit: false
}
}
`)
const stdout = await collectStdoutFromDev(appDir)
expect(stdout).toMatch(experimentalHeader)
expect(stdout).toMatch(' ⨯ prerenderEarlyExit')
}) })
it('should show warning with config from object with experimental and multiple keys', async () => { it('should show warning with config from object with experimental and multiple keys', async () => {
...@@ -127,8 +141,8 @@ describe('Config Experimental Warning', () => { ...@@ -127,8 +141,8 @@ describe('Config Experimental Warning', () => {
const stdout = await collectStdoutFromDev(appDir) const stdout = await collectStdoutFromDev(appDir)
expect(stdout).toContain(experimentalHeader) expect(stdout).toContain(experimentalHeader)
expect(stdout).toContain(' · workerThreads') expect(stdout).toContain(' ✓ workerThreads')
expect(stdout).toContain(' · scrollRestoration') expect(stdout).toContain(' ✓ scrollRestoration')
}) })
;(process.env.TURBOPACK_DEV ? describe.skip : describe)( ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode', 'production mode',
...@@ -163,6 +177,7 @@ describe('Config Experimental Warning', () => { ...@@ -163,6 +177,7 @@ describe('Config Experimental Warning', () => {
workerThreads: true, workerThreads: true,
scrollRestoration: true, scrollRestoration: true,
parallelServerCompiles: true, parallelServerCompiles: true,
prerenderEarlyExit: false,
cpus: 2, cpus: 2,
} }
} }
...@@ -170,9 +185,10 @@ describe('Config Experimental Warning', () => { ...@@ -170,9 +185,10 @@ describe('Config Experimental Warning', () => {
const stdout = await collectStdoutFromBuild(appDir) const stdout = await collectStdoutFromBuild(appDir)
expect(stdout).toMatch(experimentalHeader) expect(stdout).toMatch(experimentalHeader)
expect(stdout).toMatch(' · cpus') expect(stdout).toMatch(' · cpus')
expect(stdout).toMatch(' · workerThreads') expect(stdout).toMatch(' ✓ workerThreads')
expect(stdout).toMatch(' · scrollRestoration') expect(stdout).toMatch(' ✓ scrollRestoration')
expect(stdout).toMatch(' · parallelServerCompiles') expect(stdout).toMatch(' ⨯ prerenderEarlyExit')
expect(stdout).toMatch(' ✓ parallelServerCompiles')
}) })
it('should show unrecognized experimental features in warning but not in start log experiments section', async () => { it('should show unrecognized experimental features in warning but not in start log experiments section', async () => {
......
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