Skip to content

Commit 7f83571

Browse files
authored
fix(next): fix hmr, bump minimum required next.js 16 version to 16.2.2 (#16202)
Next.js <16.2.2 requires the `--no-server-fast-refresh` flag appended to the `next dev` command in order for HMR to work. In 16.2.2, we can now set `experimental.enableServerFastRefresh` to disable server fast refresh, which fixes HMR for all users, without requiring a new flag. This PR: - bumps the minimum required Next.js 16 version to 16.2.2 - sets `experimental.enableServerFastRefresh` if Next.js >=16.2.2 is detected - bumps Next.js to 16.2.2 in our monorepo and all templates - logs a console warning for all users using Next.js 16 - 16.2.1 After release, we'll remove the `--no-server-fast-refresh` flag from our templates in a separate PR. We cannot do it in this PR, as a newer Payload version is required --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1213971891044433
1 parent 59af156 commit 7f83571

18 files changed

Lines changed: 2087 additions & 2059 deletions

File tree

docs/getting-started/installation.mdx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Payload requires the following software:
1616
- `15.2.9` - `15.2.x`
1717
- `15.3.9` - `15.3.x`
1818
- `15.4.11` - `15.4.x`
19-
- `16.2.0`+
19+
- `16.2.2`+
2020
- Any [compatible database](/docs/database/overview) (MongoDB, Postgres or SQLite)
2121

2222
<Banner type="warning">
@@ -25,17 +25,6 @@ Payload requires the following software:
2525
sure you're using one of the supported version ranges listed above.
2626
</Banner>
2727

28-
<Banner type="warning">
29-
**Next.js 16.2+:** Server fast refresh (enabled by default) breaks Payload HMR - config changes won't propagate until a full server restart. Add `--no-server-fast-refresh` to your dev command as a workaround:
30-
31-
```bash
32-
next dev --no-server-fast-refresh
33-
```
34-
35-
This is a temporary workaround until the upstream issue is resolved.
36-
37-
</Banner>
38-
3928
<Banner type="info">
4029
**Cache Components:** While Next.js `cacheComponents` can be enabled alongside
4130
Payload without causing errors in the admin panel, full compatibility is not

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"@ai-sdk/openai": "3.0.30",
180180
"@axe-core/playwright": "4.11.0",
181181
"@libsql/client": "0.14.0",
182-
"@next/bundle-analyzer": "16.2.1",
182+
"@next/bundle-analyzer": "16.2.2",
183183
"@payloadcms/db-postgres": "workspace:*",
184184
"@payloadcms/eslint-config": "workspace:*",
185185
"@payloadcms/eslint-plugin": "workspace:*",
@@ -218,7 +218,7 @@
218218
"lint-staged": "15.2.7",
219219
"minimist": "1.2.8",
220220
"mongoose": "8.15.1",
221-
"next": "16.2.1",
221+
"next": "16.2.2",
222222
"node-gyp": "12.2.0",
223223
"open": "^10.1.0",
224224
"p-limit": "^5.0.0",

packages/next/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
"@babel/preset-env": "7.27.2",
132132
"@babel/preset-react": "7.27.1",
133133
"@babel/preset-typescript": "7.27.1",
134-
"@next/eslint-plugin-next": "16.2.1",
134+
"@next/eslint-plugin-next": "16.2.2",
135135
"@payloadcms/eslint-config": "workspace:*",
136136
"@types/busboy": "1.5.4",
137137
"@types/react": "19.2.9",
@@ -145,7 +145,7 @@
145145
},
146146
"peerDependencies": {
147147
"graphql": "^16.8.1",
148-
"next": ">=15.2.9 <15.3.0 || >=15.3.9 <15.4.0 || >=15.4.11 <15.5.0 || >=16.2.0-canary.10 <17.0.0",
148+
"next": ">=15.2.9 <15.3.0 || >=15.3.9 <15.4.0 || >=15.4.11 <15.5.0 || >=16.2.2 <17.0.0",
149149
"payload": "workspace:*"
150150
},
151151
"engines": {

packages/next/src/withPayload/withPayload.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import {
88
getNextjsVersion,
9+
supportsServerFastRefreshConfig,
910
supportsTurbopackExternalizeTransitiveDependencies,
1011
} from './withPayload.utils.js'
1112
import { withPayloadLegacy } from './withPayloadLegacy.js'
@@ -24,12 +25,13 @@ export const withPayload = (nextConfig = {}, options = {}) => {
2425
const nextjsVersion = getNextjsVersion()
2526

2627
const supportsTurbopackBuild = supportsTurbopackExternalizeTransitiveDependencies(nextjsVersion)
28+
const hasServerFastRefreshConfigOption = supportsServerFastRefreshConfig(nextjsVersion)
2729

2830
const env = nextConfig.env || {}
2931

3032
if (nextConfig.experimental?.staleTimes?.dynamic) {
3133
console.warn(
32-
'Payload detected a non-zero value for the `staleTimes.dynamic` option in your Next.js config. This will slow down page transitions and may cause stale data to load within the Admin panel. To clear this warning, remove the `staleTimes.dynamic` option from your Next.js config or set it to 0. In the future, Next.js may support scoping this option to specific routes.',
34+
'Payload: detected a non-zero value for the `staleTimes.dynamic` option in your Next.js config. This will slow down page transitions and may cause stale data to load within the Admin panel. To clear this warning, remove the `staleTimes.dynamic` option from your Next.js config or set it to 0. In the future, Next.js may support scoping this option to specific routes.',
3335
)
3436
env.NEXT_PUBLIC_ENABLE_ROUTER_CACHE_REFRESH = 'true'
3537
}
@@ -38,6 +40,12 @@ export const withPayload = (nextConfig = {}, options = {}) => {
3840
env.PAYLOAD_CACHE_COMPONENTS_ENABLED = 'true'
3941
}
4042

43+
if (nextjsVersion?.major === 16 && !hasServerFastRefreshConfigOption) {
44+
console.warn(
45+
'Payload: You are using an unsupported Next.js 16 version. You can find the supported Next.js versions here: https://payloadcms.com/docs/getting-started/installation',
46+
)
47+
}
48+
4149
const consoleWarn = console.warn
4250

4351
const sassWarningTexts = [
@@ -61,6 +69,11 @@ export const withPayload = (nextConfig = {}, options = {}) => {
6169
const baseConfig = {
6270
...nextConfig,
6371
env,
72+
experimental: {
73+
...(nextConfig.experimental || {}),
74+
// Server fast refresh breaks HMR
75+
...(hasServerFastRefreshConfigOption ? { enableServerFastRefresh: false } : {}),
76+
},
6477
sassOptions: {
6578
...(nextConfig.sassOptions || {}),
6679
/**

packages/next/src/withPayload/withPayload.utils.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,39 @@ export function getNextjsVersion() {
106106
}
107107
}
108108

109+
/**
110+
* Checks if the current Next.js version supports the `experimental.serverFastRefresh` option.
111+
* This was introduced in Next.js v16.2.2
112+
* @param {SemVer | undefined} version
113+
* @returns {boolean}
114+
*/
115+
export function supportsServerFastRefreshConfig(version) {
116+
if (!version) {
117+
return false
118+
}
119+
120+
const { major, minor, patch } = version
121+
122+
if (major === undefined || minor === undefined || patch === undefined) {
123+
return false
124+
}
125+
126+
if (major > 16) {
127+
return true
128+
}
129+
130+
if (major === 16) {
131+
if (minor > 2) {
132+
return true
133+
}
134+
if (minor === 2) {
135+
return patch >= 2
136+
}
137+
}
138+
139+
return false
140+
}
141+
109142
/**
110143
* Checks if the current Next.js version supports Turbopack externalize transitive dependencies.
111144
* This was introduced in Next.js v16.1.0-canary.3

packages/next/src/withPayload/withPayloadLegacy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const withPayloadLegacy = (nextConfig = {}) => {
4747

4848
if (isBuild && (isTurbopackNextjs15 || isTurbopackNextjs16)) {
4949
throw new Error(
50-
'Your Next.js version does not support using Turbopack for production builds. The *minimum* Next.js version required for Turbopack Builds is 16.1.0. Please upgrade to the latest supported Next.js version to resolve this error.',
50+
'Payload: Your Next.js version does not support using Turbopack for production builds. The *minimum* Next.js version required for Turbopack Builds is 16.1.0. Please upgrade to the latest supported Next.js version to resolve this error.',
5151
)
5252
}
5353

packages/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
"payload": "workspace:*"
179179
},
180180
"peerDependencies": {
181-
"next": ">=15.2.9 <15.3.0 || >=15.3.9 <15.4.0 || >=15.4.11 <15.5.0 || >=16.2.0-canary.10 <17.0.0",
181+
"next": ">=15.2.9 <15.3.0 || >=15.3.9 <15.4.0 || >=15.4.11 <15.5.0 || >=16.2.2 <17.0.0",
182182
"payload": "workspace:*",
183183
"react": "^19.0.1 || ^19.1.2 || ^19.2.1",
184184
"react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1"

0 commit comments

Comments
 (0)