Commit fb1e8283 authored by Arunoda Susiripala's avatar Arunoda Susiripala Committed by Guillermo Rauch

Wait until webpack updates before eval the JSON page. (#1511)

parent 75028b6a
......@@ -7,6 +7,8 @@ import PQueue from '../p-queue'
import { loadGetInitialProps, getURL } from '../utils'
import { _notifyBuildIdMismatch } from './'
const webpackModule = module
if (typeof window !== 'undefined' && typeof navigator.serviceWorker !== 'undefined') {
navigator.serviceWorker.getRegistrations()
.then(registrations => {
......@@ -296,7 +298,7 @@ export default class Router {
}
const newData = {
...loadComponent(jsonData),
...await loadComponent(jsonData),
jsonPageRes
}
......@@ -378,7 +380,19 @@ function toRoute (path) {
return path.replace(/\/$/, '') || '/'
}
function loadComponent (jsonData) {
async function loadComponent (jsonData) {
if (webpackModule && webpackModule.hot && webpackModule.hot.status() !== 'idle') {
await new Promise((resolve) => {
const check = (status) => {
if (status === 'idle') {
webpackModule.hot.removeStatusHandler(check)
resolve()
}
}
webpackModule.hot.status(check)
})
}
const module = evalScript(jsonData.component)
const Component = module.default || module
......
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