Skip to content

Commit 1d21428

Browse files
authored
Merge pull request #1008 from redfin/bugfix/larger-than-expected-bundle-files
larger than expected bundle files
2 parents 7f9feaa + 3ffb291 commit 1d21428

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

package-lock.json

+13-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-server-cli/src/compileClient.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,15 @@ module.exports = {
213213
return {
214214
done: function(cb) {`);
215215
if (isClient) {
216-
// No need for require.ensure() here because we are already splitting code based on the routes by having
217-
// multiple entry points. Using require.ensure() or import() will create unnecessary bundles as well
218-
// as confuse the browser because it will load some JS/CSS files via FLAB and some via Webpack's
219-
// dynamic loader. Best to just stick with the basic implementation.
220-
routesOutput.push(`cb(unwrapEs6Module(require(${relativePathToPage})));`);
216+
// Turns out, for now, we do need to keep require.ensure() here. This should be migrated to
217+
// use import() in the future, but there's an issue with Babel not recognizing import() without
218+
// another plugin: https://babeljs.io/docs/en/babel-plugin-syntax-dynamic-import/#installation
219+
// The JS/CSS files loaded by FLAB are the entrypoint/initial files. Webpack's dynamic loader
220+
// handles loading the other chunks.
221+
routesOutput.push(`
222+
require.ensure(${relativePathToPage}, function() {
223+
cb(unwrapEs6Module(require(${relativePathToPage})));
224+
});`);
221225
} else {
222226
routesOutput.push(`
223227
try {

packages/react-server-integration-tests/src/__tests__/css/CssSpec.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ describe("A CSS page", () => {
1010

1111
describe("can apply a css class", () => {
1212
helper.testWithDocument("/css", (document) => {
13-
expect(document.querySelector("head link[rel=stylesheet]").href).toMatch(/route0\.css/);
13+
// The way Webpack is chunking the CSS files, the client transition might look for 0.css while
14+
// the server side looks for route0.css
15+
expect(document.querySelector("head link[rel=stylesheet]").href).toMatch(/(?:route)?0\.css/);
1416
});
1517
});
1618

@@ -26,9 +28,11 @@ describe("A CSS page with assets", () => {
2628

2729
describe("can apply a css class", () => {
2830
helper.testWithDocument("/cssWithAssets", (document) => {
29-
// this test is really just to make sure that react-server-cli doesn't explode
30-
// when compiling CSS that includes images and fonts.
31-
expect(document.querySelector("head link[rel=stylesheet]").href).toMatch(/route0\.css/);
31+
// this test is really just to make sure that react-server-cli doesn't explode
32+
// when compiling CSS that includes images and fonts.
33+
// The way Webpack is chunking the CSS files, the client transition might look for 0.css while
34+
// the server side looks for route0.css
35+
expect(document.querySelector("head link[rel=stylesheet]").href).toMatch(/(?:route)?0\.css/);
3236
});
3337
});
3438

0 commit comments

Comments
 (0)