1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

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

This commit is contained in:
Arunoda Susiripala 2017-03-27 02:08:55 +05:30 committed by Guillermo Rauch
parent 75028b6a8f
commit fb1e828318

View file

@ -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