Skip to content
This repository was archived by the owner on Dec 7, 2018. It is now read-only.

Commit 4a7b36d

Browse files
author
Sergey Tatarintsev
committed
fix: crash in lazy mode
In lazy mode, res.locals.webpackStats is undefined
1 parent af6cb8d commit 4a7b36d

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

lib/router.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@ function testPathToChunkUrl(testPath) {
2727
*/
2828
function middleware(routeBuilder) {
2929
return function middleware(req, res, next) {
30-
const commonAssetsObj = _.omitBy(
31-
res.locals.webpackStats.toJson().assetsByChunkName,
32-
value => /\.bundle.js$/.test(value)
33-
);
34-
const commonAssets = Object.keys(commonAssetsObj).reduce((result, item) => {
35-
result.push(assetsRoot() + commonAssetsObj[item]);
36-
return result;
37-
}, []);
38-
30+
const commonAssets = readCommonAssets(res.locals.webpackStats);
3931
log(`request to ${req.path}`);
4032
if (routeBuilder.isUrlRegistered(req.path)) {
4133
log('this is a test page url');
@@ -48,6 +40,19 @@ function middleware(routeBuilder) {
4840
};
4941
}
5042

43+
function readCommonAssets(webpackStats) {
44+
if (!webpackStats) {
45+
return [];
46+
}
47+
const commonAssetsObj = _.omitBy(
48+
webpackStats.toJson().assetsByChunkName,
49+
value => /\.bundle.js$/.test(value)
50+
);
51+
return Object.keys(commonAssetsObj).reduce((result, item) => {
52+
result.push(assetsRoot() + commonAssetsObj[item]);
53+
return result;
54+
}, []);
55+
}
5156

5257
exports.testPathToChunkName = testPathToChunkName;
5358
exports.testPathToChunkUrl = testPathToChunkUrl;

0 commit comments

Comments
 (0)