Skip to content

Commit

Permalink
Fix logging removed experiments in start logs (#57373)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
huozhi authored Oct 25, 2023
1 parent d8160e0 commit 9c87ea5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ export interface ExperimentalConfig {

/**
* 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
*/
typedRoutes?: boolean
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,9 @@ export function getEnabledExperimentalFeatures(
userNextConfigExperimental
) as (keyof ExperimentalConfig)[]) {
if (
featureName in defaultConfig.experimental &&
userNextConfigExperimental[featureName] !==
defaultConfig.experimental[featureName]
defaultConfig.experimental[featureName]
) {
enabledExperiments.push(featureName)
}
Expand Down
44 changes: 39 additions & 5 deletions test/integration/config-experimental-warning/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
File,
nextBuild,
nextStart,
check,
} from 'next-test-utils'
import stripAnsi from 'strip-ansi'

const appDir = join(__dirname, '..')
const configFile = new File(join(appDir, '/next.config.js'))
Expand Down Expand Up @@ -107,8 +109,8 @@ describe('Config Experimental Warning', () => {
`)

const stdout = await collectStdoutFromDev(appDir)
expect(stdout).not.toMatch(' - Experiments (use at your own risk):')
expect(stdout).not.toMatch(' · workerThreads')
expect(stdout).not.toContain(' - Experiments (use at your own risk):')
expect(stdout).not.toContain(' · workerThreads')
})

it('should show warning with config from object with experimental and multiple keys', async () => {
Expand All @@ -122,9 +124,9 @@ describe('Config Experimental Warning', () => {
`)

const stdout = await collectStdoutFromDev(appDir)
expect(stdout).toMatch(' - Experiments (use at your own risk):')
expect(stdout).toMatch(' · workerThreads')
expect(stdout).toMatch(' · scrollRestoration')
expect(stdout).toContain(' - Experiments (use at your own risk):')
expect(stdout).toContain(' · workerThreads')
expect(stdout).toContain(' · scrollRestoration')
})

it('should not show next app info in next start', async () => {
Expand Down Expand Up @@ -168,4 +170,36 @@ describe('Config Experimental Warning', () => {
expect(stdout).toMatch(' · scrollRestoration')
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"`
)
})
})
})

0 comments on commit 9c87ea5

Please sign in to comment.