Skip to content

Commit

Permalink
fix: infinity loop for multi compiler mode (#3840)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 13, 2021
1 parent fa593b5 commit e019bd2
Show file tree
Hide file tree
Showing 25 changed files with 584 additions and 186 deletions.
2 changes: 1 addition & 1 deletion client-src/utils/reloadApp.js
Expand Up @@ -15,7 +15,7 @@ function reloadApp({ hot, liveReload }, status) {
? // eslint-disable-next-line camelcase
__webpack_hash__
: status.previousHash || "";
const isInitial = status.currentHash.indexOf(webpackHash) === 0;
const isInitial = status.currentHash.indexOf(webpackHash) >= 0;

if (isInitial) {
const isLegacyInitial =
Expand Down
30 changes: 11 additions & 19 deletions lib/Server.js
Expand Up @@ -1150,26 +1150,18 @@ class Server {
}

setupHooks() {
const addHooks = (compiler) => {
compiler.hooks.invalid.tap("webpack-dev-server", () => {
if (this.webSocketServer) {
this.sendMessage(this.webSocketServer.clients, "invalid");
}
});
compiler.hooks.done.tap("webpack-dev-server", (stats) => {
if (this.webSocketServer) {
this.sendStats(this.webSocketServer.clients, this.getStats(stats));
}

this.stats = stats;
});
};
this.compiler.hooks.invalid.tap("webpack-dev-server", () => {
if (this.webSocketServer) {
this.sendMessage(this.webSocketServer.clients, "invalid");
}
});
this.compiler.hooks.done.tap("webpack-dev-server", (stats) => {
if (this.webSocketServer) {
this.sendStats(this.webSocketServer.clients, this.getStats(stats));
}

if (this.compiler.compilers) {
this.compiler.compilers.forEach(addHooks);
} else {
addHooks(this.compiler);
}
this.stats = stats;
});
}

setupHostHeaderCheck() {
Expand Down
4 changes: 2 additions & 2 deletions test/client/utils/reloadApp.test.js
Expand Up @@ -86,7 +86,7 @@ describe("'reloadApp' function", () => {

reloadApp(
{ hot: false, hotReload: true, liveReload: true },
{ isUnloading: false, currentHash: "other-mock-hash" }
{ isUnloading: false, currentHash: "changed-mock" }
);

setTimeout(() => {
Expand All @@ -101,7 +101,7 @@ describe("'reloadApp' function", () => {
test("should run liveReload when protocol is http:", (done) => {
reloadApp(
{ hot: false, hotReload: true, liveReload: true },
{ isUnloading: false, currentHash: "other-mock-hash" }
{ isUnloading: false, currentHash: "changed-mock" }
);

setTimeout(() => {
Expand Down
94 changes: 92 additions & 2 deletions test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack4
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Multi compiler should work with multiple compilers: console messages 1`] = `
exports[`multi compiler should work with one web target configuration: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
Expand All @@ -9,4 +9,94 @@ Array [
]
`;

exports[`Multi compiler should work with multiple compilers: page errors 1`] = `Array []`;
exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = `
Array [
"one",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = `
Array [
"two",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with hot and live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with universal configurations with only hot reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = `
Array [
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`;
94 changes: 92 additions & 2 deletions test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack5
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Multi compiler should work with multiple compilers: console messages 1`] = `
exports[`multi compiler should work with one web target configuration: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
Expand All @@ -9,4 +9,94 @@ Array [
]
`;

exports[`Multi compiler should work with multiple compilers: page errors 1`] = `Array []`;
exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = `
Array [
"one",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = `
Array [
"two",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with hot and live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with universal configurations with only hot reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = `
Array [
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`;
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;
exports[`universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;

exports[`Universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;
exports[`universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;

exports[`Universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;
exports[`universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;

exports[`Universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
exports[`universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;
exports[`universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;

exports[`Universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;
exports[`universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;

exports[`Universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;
exports[`universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;

exports[`Universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
exports[`universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
2 changes: 1 addition & 1 deletion test/e2e/module-federation.test.js
Expand Up @@ -8,7 +8,7 @@ const objectEntryConfig = require("../fixtures/module-federation-config/webpack.
const multiConfig = require("../fixtures/module-federation-config/webpack.multi.config");
const runBrowser = require("../helpers/run-browser");
const isWebpack5 = require("../helpers/isWebpack5");
const port = require("../ports-map")["universal-compiler"];
const port = require("../ports-map")["module-federation"];

const describeOnlyWebpack5 = isWebpack5 ? describe : describe.skip;

Expand Down

0 comments on commit e019bd2

Please sign in to comment.