Skip to content

Commit fb1e828

Browse files
arunodarauchg
authored andcommitted
Wait until webpack updates before eval the JSON page. (vercel#1511)
1 parent 75028b6 commit fb1e828

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/router/router.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import PQueue from '../p-queue'
77
import { loadGetInitialProps, getURL } from '../utils'
88
import { _notifyBuildIdMismatch } from './'
99

10+
const webpackModule = module
11+
1012
if (typeof window !== 'undefined' && typeof navigator.serviceWorker !== 'undefined') {
1113
navigator.serviceWorker.getRegistrations()
1214
.then(registrations => {
@@ -296,7 +298,7 @@ export default class Router {
296298
}
297299

298300
const newData = {
299-
...loadComponent(jsonData),
301+
...await loadComponent(jsonData),
300302
jsonPageRes
301303
}
302304

@@ -378,7 +380,19 @@ function toRoute (path) {
378380
return path.replace(/\/$/, '') || '/'
379381
}
380382

381-
function loadComponent (jsonData) {
383+
async function loadComponent (jsonData) {
384+
if (webpackModule && webpackModule.hot && webpackModule.hot.status() !== 'idle') {
385+
await new Promise((resolve) => {
386+
const check = (status) => {
387+
if (status === 'idle') {
388+
webpackModule.hot.removeStatusHandler(check)
389+
resolve()
390+
}
391+
}
392+
webpackModule.hot.status(check)
393+
})
394+
}
395+
382396
const module = evalScript(jsonData.component)
383397
const Component = module.default || module
384398

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy