-
Notifications
You must be signed in to change notification settings - Fork 31.2k
Add deprecation warning to Runtime config #84168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
50a8179
83bac4b
89d7c0a
192ef57
5a50696
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| 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') | ||
| })() |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,15 @@ | ||||||||
| let runtimeConfig: any | ||||||||
|
|
||||||||
| /** | ||||||||
| * @deprecated Runtime config is deprecated and will be removed in Next.js 16. | ||||||||
| */ | ||||||||
| export default () => { | ||||||||
| return runtimeConfig | ||||||||
| } | ||||||||
|
Comment on lines
+3
to
8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do a runtime warning here as well?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have internals that call this resulting warning regardless of whether the users set the value on the config. 🤔
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do we export these methods? Can the publicly available function just wrap this one with a runtime warning? There we should set the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can modify from here next.js/packages/next/config.d.ts Lines 1 to 3 in f9248ea
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We're not going to use it when we remove; the internal usages are setConfig for the user to use when getConfig. |
||||||||
|
|
||||||||
| /** | ||||||||
| * @deprecated Runtime config is deprecated and will be removed in Next.js 16. | ||||||||
| */ | ||||||||
| export function setConfig(configValue: any): void { | ||||||||
| runtimeConfig = configValue | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { ReactNode } from 'react' | ||
| export default function Root({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <html> | ||
| <body>{children}</body> | ||
| </html> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import getConfig from 'next/config' | ||
|
|
||
| export default function Page() { | ||
| getConfig() | ||
| return <p>hello world</p> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| 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.' | ||
| ) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** | ||
| * @type {import('next').NextConfig} | ||
| */ | ||
| const nextConfig = { | ||
| publicRuntimeConfig: { | ||
| foo: 'bar', | ||
| }, | ||
| serverRuntimeConfig: { | ||
| foo: 'bar', | ||
| }, | ||
| } | ||
|
|
||
| module.exports = nextConfig |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| /** @type {import('next').NextConfig} */ | ||
| module.exports = { | ||
| // Explicitly configure deprecated options | ||
| experimental: { | ||
| instrumentationHook: true, | ||
| }, | ||
| publicRuntimeConfig: { | ||
| foo: 'bar', | ||
| }, | ||
| serverRuntimeConfig: { | ||
| foo: 'bar', | ||
| }, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any tests ensuring these are logged as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For deprecation warnings no, can follow up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh we do have
test/e2e/deprecation-warnings/deprecation-warnings.test.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests