diff --git a/lib/router/router.js b/lib/router/router.js index 2c46e3ff..3c477b20 100644 --- a/lib/router/router.js +++ b/lib/router/router.js @@ -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