From fb1e82831871f21259885f3c4f0ba1767d5a56ae Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Mon, 27 Mar 2017 02:08:55 +0530 Subject: [PATCH] Wait until webpack updates before eval the JSON page. (#1511) --- lib/router/router.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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