Unverified Commit 9c87ea5a authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix logging removed experiments in start logs (#57373)

Do not log the removed experiments in the start server logs, for instance `experimental.appDir` should get warned as unexpected option but it's not the valid experiment anymore
parent d8160e05
...@@ -277,7 +277,6 @@ export interface ExperimentalConfig { ...@@ -277,7 +277,6 @@ export interface ExperimentalConfig {
/** /**
* Generate Route types and enable type checking for Link and Router.push, etc. * Generate Route types and enable type checking for Link and Router.push, etc.
* This option requires `appDir` to be enabled first.
* @see https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes * @see https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes
*/ */
typedRoutes?: boolean typedRoutes?: boolean
......
...@@ -1084,8 +1084,9 @@ export function getEnabledExperimentalFeatures( ...@@ -1084,8 +1084,9 @@ export function getEnabledExperimentalFeatures(
userNextConfigExperimental userNextConfigExperimental
) as (keyof ExperimentalConfig)[]) { ) as (keyof ExperimentalConfig)[]) {
if ( if (
featureName in defaultConfig.experimental &&
userNextConfigExperimental[featureName] !== userNextConfigExperimental[featureName] !==
defaultConfig.experimental[featureName] defaultConfig.experimental[featureName]
) { ) {
enabledExperiments.push(featureName) enabledExperiments.push(featureName)
} }
......
...@@ -8,7 +8,9 @@ import { ...@@ -8,7 +8,9 @@ import {
File, File,
nextBuild, nextBuild,
nextStart, nextStart,
check,
} from 'next-test-utils' } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
const configFile = new File(join(appDir, '/next.config.js')) const configFile = new File(join(appDir, '/next.config.js'))
...@@ -107,8 +109,8 @@ describe('Config Experimental Warning', () => { ...@@ -107,8 +109,8 @@ describe('Config Experimental Warning', () => {
`) `)
const stdout = await collectStdoutFromDev(appDir) const stdout = await collectStdoutFromDev(appDir)
expect(stdout).not.toMatch(' - Experiments (use at your own risk):') expect(stdout).not.toContain(' - Experiments (use at your own risk):')
expect(stdout).not.toMatch(' · workerThreads') expect(stdout).not.toContain(' · workerThreads')
}) })
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 () => {
...@@ -122,9 +124,9 @@ describe('Config Experimental Warning', () => { ...@@ -122,9 +124,9 @@ describe('Config Experimental Warning', () => {
`) `)
const stdout = await collectStdoutFromDev(appDir) const stdout = await collectStdoutFromDev(appDir)
expect(stdout).toMatch(' - Experiments (use at your own risk):') expect(stdout).toContain(' - Experiments (use at your own risk):')
expect(stdout).toMatch(' · workerThreads') expect(stdout).toContain(' · workerThreads')
expect(stdout).toMatch(' · scrollRestoration') expect(stdout).toContain(' · scrollRestoration')
}) })
it('should not show next app info in next start', async () => { it('should not show next app info in next start', async () => {
...@@ -168,4 +170,36 @@ describe('Config Experimental Warning', () => { ...@@ -168,4 +170,36 @@ describe('Config Experimental Warning', () => {
expect(stdout).toMatch(' · scrollRestoration') expect(stdout).toMatch(' · scrollRestoration')
expect(stdout).toMatch(' · instrumentationHook') expect(stdout).toMatch(' · instrumentationHook')
}) })
it('should show unrecognized experimental features in warning but not in start log experiments section', async () => {
configFile.write(`
module.exports = {
experimental: {
appDir: true
}
}
`)
await collectStdoutFromBuild(appDir)
const port = await findPort()
let stdout = ''
let stderr = ''
app = await nextStart(appDir, port, {
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
})
await check(() => {
const cliOutput = stripAnsi(stdout)
const cliOutputErr = stripAnsi(stderr)
expect(cliOutput).not.toContain(' - Experiments (use at your own risk):')
expect(cliOutputErr).toContain(
`Unrecognized key(s) in object: 'appDir' at "experimental"`
)
})
})
}) })
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