Skip to content

Commit 013844c

Browse files
authored
Fix "apply() is only allowed in ready status (state: idle)" HMR errors (vercel#43242)
This is a follow-up to vercel#43145 that fixes [this issue](vercel#43145 (comment)): ``` warn - Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works Error: apply() is only allowed in ready status (state: idle) at https://app.airplane.so:5000/_next/static/chunks/webpack.js?ts=1669127927262:615:21 ``` ## Bug - [X] Related issues linked using `fixes #number` - n/a - [X] Integration tests added - n/a - [X] Errors have a helpful link attached, see `contributing.md` - n/a
1 parent 2085dac commit 013844c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/next/client/components/react-dev-overlay/hot-reloader-client.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function tryApplyUpdates(
144144
return
145145
}
146146

147-
const hasUpdates = Boolean(updatedModules?.length)
147+
const hasUpdates = Boolean(updatedModules.length)
148148
if (typeof onHotUpdateSuccess === 'function') {
149149
// Maybe we want to do something.
150150
onHotUpdateSuccess(hasUpdates)
@@ -176,16 +176,20 @@ function tryApplyUpdates(
176176
module.hot
177177
.check(/* autoApply */ false)
178178
.then((updatedModules: any[] | null) => {
179-
const hasUpdates = Boolean(updatedModules?.length)
179+
if (!updatedModules) {
180+
return null
181+
}
182+
180183
if (typeof onBeforeUpdate === 'function') {
184+
const hasUpdates = Boolean(updatedModules.length)
181185
onBeforeUpdate(hasUpdates)
182186
}
183187
// https://webpack.js.org/api/hot-module-replacement/#apply
184188
// @ts-expect-error module.hot exists
185189
return module.hot.apply()
186190
})
187191
.then(
188-
(updatedModules: any) => {
192+
(updatedModules: any[] | null) => {
189193
handleApplyUpdates(null, updatedModules)
190194
},
191195
(err: any) => {

packages/next/client/dev/error-overlay/hot-dev-client.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ function tryApplyUpdates(onBeforeHotUpdate, onHotUpdateSuccess) {
337337
return
338338
}
339339

340-
const hasUpdates = Boolean(updatedModules?.length)
340+
const hasUpdates = Boolean(updatedModules.length)
341341
if (typeof onHotUpdateSuccess === 'function') {
342342
// Maybe we want to do something.
343343
onHotUpdateSuccess(hasUpdates)
@@ -367,8 +367,12 @@ function tryApplyUpdates(onBeforeHotUpdate, onHotUpdateSuccess) {
367367
module.hot
368368
.check(/* autoApply */ false)
369369
.then((updatedModules) => {
370+
if (!updatedModules) {
371+
return null
372+
}
373+
370374
if (typeof onBeforeHotUpdate === 'function') {
371-
const hasUpdates = Boolean(updatedModules?.length)
375+
const hasUpdates = Boolean(updatedModules.length)
372376
onBeforeHotUpdate(hasUpdates)
373377
}
374378
return module.hot.apply()

0 commit comments

Comments
 (0)