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:
parent
75028b6a8f
commit
fb1e828318
|
@ -7,6 +7,8 @@ import PQueue from '../p-queue'
|
||||||
import { loadGetInitialProps, getURL } from '../utils'
|
import { loadGetInitialProps, getURL } from '../utils'
|
||||||
import { _notifyBuildIdMismatch } from './'
|
import { _notifyBuildIdMismatch } from './'
|
||||||
|
|
||||||
|
const webpackModule = module
|
||||||
|
|
||||||
if (typeof window !== 'undefined' && typeof navigator.serviceWorker !== 'undefined') {
|
if (typeof window !== 'undefined' && typeof navigator.serviceWorker !== 'undefined') {
|
||||||
navigator.serviceWorker.getRegistrations()
|
navigator.serviceWorker.getRegistrations()
|
||||||
.then(registrations => {
|
.then(registrations => {
|
||||||
|
@ -296,7 +298,7 @@ export default class Router {
|
||||||
}
|
}
|
||||||
|
|
||||||
const newData = {
|
const newData = {
|
||||||
...loadComponent(jsonData),
|
...await loadComponent(jsonData),
|
||||||
jsonPageRes
|
jsonPageRes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +380,19 @@ function toRoute (path) {
|
||||||
return path.replace(/\/$/, '') || '/'
|
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 module = evalScript(jsonData.component)
|
||||||
const Component = module.default || module
|
const Component = module.default || module
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue