Skip to content

Commit c294549

Browse files
authored
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 0b74ff9 commit c294549

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
@@ -1131,14 +1131,16 @@ export interface NextConfig {
11311131
/**
11321132
* Add public (in browser) runtime configuration to your app
11331133
*
1134-
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration
1134+
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration)
1135+
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
11351136
*/
11361137
publicRuntimeConfig?: { [key: string]: any }
11371138

11381139
/**
11391140
* Add server runtime configuration to your app
11401141
*
1141-
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration
1142+
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration)
1143+
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
11421144
*/
11431145
serverRuntimeConfig?: { [key: string]: any }
11441146

packages/next/src/server/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ function checkDeprecations(
117117
silent: boolean,
118118
dir: string
119119
) {
120+
warnOptionHasBeenDeprecated(
121+
userConfig,
122+
'publicRuntimeConfig',
123+
`Runtime config is deprecated and the \`publicRuntimeConfig\` configuration option will be removed in Next.js 16.`,
124+
silent
125+
)
126+
warnOptionHasBeenDeprecated(
127+
userConfig,
128+
'serverRuntimeConfig',
129+
`Runtime config is deprecated and the \`serverRuntimeConfig\` configuration option will be removed in Next.js 16.`,
130+
silent
131+
)
132+
120133
if (userConfig.experimental?.dynamicIO !== undefined) {
121134
warnOptionHasBeenDeprecated(
122135
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
@@ -32,6 +32,14 @@ describe('deprecation-warnings', () => {
3232
// Should warn about experimental.instrumentationHook
3333
expect(logs).toContain('experimental.instrumentationHook')
3434
expect(logs).toContain('no longer needed')
35+
36+
// Should warn about publicRuntimeConfig
37+
expect(logs).toContain('publicRuntimeConfig')
38+
expect(logs).toContain('will be removed in Next.js 16')
39+
40+
// Should warn about serverRuntimeConfig
41+
expect(logs).toContain('serverRuntimeConfig')
42+
expect(logs).toContain('will be removed in Next.js 16')
3543
})
3644
})
3745
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
/** @type {import('next').NextConfig} */
12
module.exports = {
23
// Explicitly configure deprecated options
34
experimental: {
45
instrumentationHook: true,
56
},
7+
publicRuntimeConfig: {
8+
foo: 'bar',
9+
},
10+
serverRuntimeConfig: {
11+
foo: 'bar',
12+
},
613
}

0 commit comments

Comments
 (0)