Skip to content

Commit 00ebf1b

Browse files
committed
[backport] Add deprecation warning to Runtime config (#84168)
Following up on #84167, adding a deprecation warning for the Runtime config. This PR will be backported to v15.
1 parent 40f1d78 commit 00ebf1b

File tree

10 files changed

+93
-3
lines changed

10 files changed

+93
-3
lines changed

packages/next/config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
module.exports = require('./dist/shared/lib/runtime-config.external')
1+
let hasWarned = false
2+
3+
module.exports = (() => {
4+
if (!hasWarned) {
5+
console.warn(
6+
// ANSI code aligns with Next.js warning style from picocolors.
7+
' \x1b[33m\x1b[1m⚠\x1b[22m\x1b[39m Runtime config is deprecated and will be removed in Next.js 16. Please remove the usage of "next/config" from your project.'
8+
)
9+
hasWarned = true
10+
}
11+
return require('./dist/shared/lib/runtime-config.external')
12+
})()

packages/next/src/server/config-shared.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,14 +1235,16 @@ export interface NextConfig extends Record<string, any> {
12351235
/**
12361236
* Add public (in browser) runtime configuration to your app
12371237
*
1238-
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration
1238+
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration)
1239+
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
12391240
*/
12401241
publicRuntimeConfig?: { [key: string]: any }
12411242

12421243
/**
12431244
* Add server runtime configuration to your app
12441245
*
1245-
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration
1246+
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration)
1247+
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
12461248
*/
12471249
serverRuntimeConfig?: { [key: string]: any }
12481250

packages/next/src/server/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ function checkDeprecations(
109109
silent
110110
)
111111

112+
warnOptionHasBeenDeprecated(
113+
userConfig,
114+
'publicRuntimeConfig',
115+
`Runtime config is deprecated and the \`publicRuntimeConfig\` configuration option will be removed in Next.js 16.`,
116+
silent
117+
)
118+
warnOptionHasBeenDeprecated(
119+
userConfig,
120+
'serverRuntimeConfig',
121+
`Runtime config is deprecated and the \`serverRuntimeConfig\` configuration option will be removed in Next.js 16.`,
122+
silent
123+
)
124+
112125
if (userConfig.experimental?.dynamicIO !== undefined) {
113126
warnOptionHasBeenDeprecated(
114127
userConfig,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
let runtimeConfig: any
22

3+
/**
4+
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
5+
*/
36
export default () => {
47
return runtimeConfig
58
}
69

10+
/**
11+
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
12+
*/
713
export function setConfig(configValue: any): void {
814
runtimeConfig = configValue
915
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ReactNode } from 'react'
2+
export default function Root({ children }: { children: ReactNode }) {
3+
return (
4+
<html>
5+
<body>{children}</body>
6+
</html>
7+
)
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import getConfig from 'next/config'
2+
3+
export default function Page() {
4+
getConfig()
5+
return <p>hello world</p>
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
describe('deprecation-warning-runtime-config', () => {
4+
const { next } = nextTestSetup({
5+
files: __dirname,
6+
})
7+
8+
it('should warn when imported "next/config" module', async () => {
9+
// Navigate to "/" for dev server to execute the code
10+
await next.browser('/')
11+
12+
expect(next.cliOutput).toContain(
13+
'Runtime config is deprecated and will be removed in Next.js 16. Please remove the usage of "next/config" from your project.'
14+
)
15+
})
16+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {
5+
publicRuntimeConfig: {
6+
foo: 'bar',
7+
},
8+
serverRuntimeConfig: {
9+
foo: 'bar',
10+
},
11+
}
12+
13+
module.exports = nextConfig

test/e2e/deprecation-warnings/deprecation-warnings.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ describe('deprecation-warnings', () => {
3535
// Should warn about experimental.instrumentationHook
3636
expect(logs).toContain('experimental.instrumentationHook')
3737
expect(logs).toContain('no longer needed')
38+
39+
// Should warn about publicRuntimeConfig
40+
expect(logs).toContain('publicRuntimeConfig')
41+
expect(logs).toContain('will be removed in Next.js 16')
42+
43+
// Should warn about serverRuntimeConfig
44+
expect(logs).toContain('serverRuntimeConfig')
45+
expect(logs).toContain('will be removed in Next.js 16')
3846
})
3947
})
4048
})

test/e2e/deprecation-warnings/fixtures/with-deprecated-config/next.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @type {import('next').NextConfig} */
12
module.exports = {
23
// Explicitly configure deprecated options
34
amp: {
@@ -6,4 +7,10 @@ module.exports = {
67
experimental: {
78
instrumentationHook: true,
89
},
10+
publicRuntimeConfig: {
11+
foo: 'bar',
12+
},
13+
serverRuntimeConfig: {
14+
foo: 'bar',
15+
},
916
}

0 commit comments

Comments
 (0)