Unverified Commit ce3d9639 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[backport] Add deprecation warning to Runtime config (#84168) (#84650)

This PR backports #84168
parent ec69752d
module.exports = require('./dist/shared/lib/runtime-config.external') let hasWarned = false
module.exports = (() => {
if (!hasWarned) {
console.warn(
// ANSI code aligns with Next.js warning style from picocolors.
' \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.'
)
hasWarned = true
}
return require('./dist/shared/lib/runtime-config.external')
})()
...@@ -1235,14 +1235,16 @@ export interface NextConfig extends Record<string, any> { ...@@ -1235,14 +1235,16 @@ export interface NextConfig extends Record<string, any> {
/** /**
* Add public (in browser) runtime configuration to your app * Add public (in browser) runtime configuration to your app
* *
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration * @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration)
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
*/ */
publicRuntimeConfig?: { [key: string]: any } publicRuntimeConfig?: { [key: string]: any }
/** /**
* Add server runtime configuration to your app * Add server runtime configuration to your app
* *
* @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration * @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration)
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
*/ */
serverRuntimeConfig?: { [key: string]: any } serverRuntimeConfig?: { [key: string]: any }
......
...@@ -109,6 +109,19 @@ function checkDeprecations( ...@@ -109,6 +109,19 @@ function checkDeprecations(
silent silent
) )
warnOptionHasBeenDeprecated(
userConfig,
'publicRuntimeConfig',
`Runtime config is deprecated and the \`publicRuntimeConfig\` configuration option will be removed in Next.js 16.`,
silent
)
warnOptionHasBeenDeprecated(
userConfig,
'serverRuntimeConfig',
`Runtime config is deprecated and the \`serverRuntimeConfig\` configuration option will be removed in Next.js 16.`,
silent
)
if (userConfig.experimental?.dynamicIO !== undefined) { if (userConfig.experimental?.dynamicIO !== undefined) {
warnOptionHasBeenDeprecated( warnOptionHasBeenDeprecated(
userConfig, userConfig,
......
let runtimeConfig: any let runtimeConfig: any
/**
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
*/
export default () => { export default () => {
return runtimeConfig return runtimeConfig
} }
/**
* @deprecated Runtime config is deprecated and will be removed in Next.js 16.
*/
export function setConfig(configValue: any): void { export function setConfig(configValue: any): void {
runtimeConfig = configValue runtimeConfig = configValue
} }
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import getConfig from 'next/config'
export default function Page() {
getConfig()
return <p>hello world</p>
}
import { nextTestSetup } from 'e2e-utils'
describe('deprecation-warning-runtime-config', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should warn when imported "next/config" module', async () => {
// Navigate to "/" for dev server to execute the code
await next.browser('/')
expect(next.cliOutput).toContain(
'Runtime config is deprecated and will be removed in Next.js 16. Please remove the usage of "next/config" from your project.'
)
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
publicRuntimeConfig: {
foo: 'bar',
},
serverRuntimeConfig: {
foo: 'bar',
},
}
module.exports = nextConfig
...@@ -35,6 +35,14 @@ describe('deprecation-warnings', () => { ...@@ -35,6 +35,14 @@ describe('deprecation-warnings', () => {
// Should warn about experimental.instrumentationHook // Should warn about experimental.instrumentationHook
expect(logs).toContain('experimental.instrumentationHook') expect(logs).toContain('experimental.instrumentationHook')
expect(logs).toContain('no longer needed') expect(logs).toContain('no longer needed')
// Should warn about publicRuntimeConfig
expect(logs).toContain('publicRuntimeConfig')
expect(logs).toContain('will be removed in Next.js 16')
// Should warn about serverRuntimeConfig
expect(logs).toContain('serverRuntimeConfig')
expect(logs).toContain('will be removed in Next.js 16')
}) })
}) })
}) })
/** @type {import('next').NextConfig} */
module.exports = { module.exports = {
// Explicitly configure deprecated options // Explicitly configure deprecated options
amp: { amp: {
...@@ -6,4 +7,10 @@ module.exports = { ...@@ -6,4 +7,10 @@ module.exports = {
experimental: { experimental: {
instrumentationHook: true, instrumentationHook: true,
}, },
publicRuntimeConfig: {
foo: 'bar',
},
serverRuntimeConfig: {
foo: 'bar',
},
} }
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