Skip to content

Commit e019bd2

Browse files
fix: infinity loop for multi compiler mode (#3840)
1 parent fa593b5 commit e019bd2

25 files changed

+584
-186
lines changed

client-src/utils/reloadApp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function reloadApp({ hot, liveReload }, status) {
1515
? // eslint-disable-next-line camelcase
1616
__webpack_hash__
1717
: status.previousHash || "";
18-
const isInitial = status.currentHash.indexOf(webpackHash) === 0;
18+
const isInitial = status.currentHash.indexOf(webpackHash) >= 0;
1919

2020
if (isInitial) {
2121
const isLegacyInitial =

lib/Server.js

+11-19
Original file line numberDiff line numberDiff line change
@@ -1150,26 +1150,18 @@ class Server {
11501150
}
11511151

11521152
setupHooks() {
1153-
const addHooks = (compiler) => {
1154-
compiler.hooks.invalid.tap("webpack-dev-server", () => {
1155-
if (this.webSocketServer) {
1156-
this.sendMessage(this.webSocketServer.clients, "invalid");
1157-
}
1158-
});
1159-
compiler.hooks.done.tap("webpack-dev-server", (stats) => {
1160-
if (this.webSocketServer) {
1161-
this.sendStats(this.webSocketServer.clients, this.getStats(stats));
1162-
}
1163-
1164-
this.stats = stats;
1165-
});
1166-
};
1153+
this.compiler.hooks.invalid.tap("webpack-dev-server", () => {
1154+
if (this.webSocketServer) {
1155+
this.sendMessage(this.webSocketServer.clients, "invalid");
1156+
}
1157+
});
1158+
this.compiler.hooks.done.tap("webpack-dev-server", (stats) => {
1159+
if (this.webSocketServer) {
1160+
this.sendStats(this.webSocketServer.clients, this.getStats(stats));
1161+
}
11671162

1168-
if (this.compiler.compilers) {
1169-
this.compiler.compilers.forEach(addHooks);
1170-
} else {
1171-
addHooks(this.compiler);
1172-
}
1163+
this.stats = stats;
1164+
});
11731165
}
11741166

11751167
setupHostHeaderCheck() {

test/client/utils/reloadApp.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe("'reloadApp' function", () => {
8686

8787
reloadApp(
8888
{ hot: false, hotReload: true, liveReload: true },
89-
{ isUnloading: false, currentHash: "other-mock-hash" }
89+
{ isUnloading: false, currentHash: "changed-mock" }
9090
);
9191

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

107107
setTimeout(() => {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

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

12-
exports[`Multi compiler should work with multiple compilers: page errors 1`] = `Array []`;
12+
exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`;
13+
14+
exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = `
15+
Array [
16+
"[HMR] Waiting for update signal from WDS...",
17+
"one",
18+
"[webpack-dev-server] Hot Module Replacement enabled.",
19+
"[webpack-dev-server] Live Reloading enabled.",
20+
]
21+
`;
22+
23+
exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = `
24+
Array [
25+
"[HMR] Waiting for update signal from WDS...",
26+
"two",
27+
"[webpack-dev-server] Hot Module Replacement enabled.",
28+
"[webpack-dev-server] Live Reloading enabled.",
29+
]
30+
`;
31+
32+
exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`;
33+
34+
exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`;
35+
36+
exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = `
37+
Array [
38+
"[HMR] Waiting for update signal from WDS...",
39+
"one",
40+
"[webpack-dev-server] Hot Module Replacement enabled.",
41+
]
42+
`;
43+
44+
exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = `
45+
Array [
46+
"[HMR] Waiting for update signal from WDS...",
47+
"two",
48+
"[webpack-dev-server] Hot Module Replacement enabled.",
49+
]
50+
`;
51+
52+
exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`;
53+
54+
exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`;
55+
56+
exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = `
57+
Array [
58+
"one",
59+
"[webpack-dev-server] Live Reloading enabled.",
60+
]
61+
`;
62+
63+
exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = `
64+
Array [
65+
"two",
66+
"[webpack-dev-server] Live Reloading enabled.",
67+
]
68+
`;
69+
70+
exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`;
71+
72+
exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`;
73+
74+
exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = `
75+
Array [
76+
"[HMR] Waiting for update signal from WDS...",
77+
"Hello from the browser",
78+
"[webpack-dev-server] Hot Module Replacement enabled.",
79+
"[webpack-dev-server] Live Reloading enabled.",
80+
]
81+
`;
82+
83+
exports[`multi compiler should work with universal configurations with hot and live reload: page errors 1`] = `Array []`;
84+
85+
exports[`multi compiler should work with universal configurations with only hot reload: console messages 1`] = `
86+
Array [
87+
"[HMR] Waiting for update signal from WDS...",
88+
"Hello from the browser",
89+
"[webpack-dev-server] Hot Module Replacement enabled.",
90+
]
91+
`;
92+
93+
exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`;
94+
95+
exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = `
96+
Array [
97+
"Hello from the browser",
98+
"[webpack-dev-server] Live Reloading enabled.",
99+
]
100+
`;
101+
102+
exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

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

12-
exports[`Multi compiler should work with multiple compilers: page errors 1`] = `Array []`;
12+
exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`;
13+
14+
exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = `
15+
Array [
16+
"[HMR] Waiting for update signal from WDS...",
17+
"one",
18+
"[webpack-dev-server] Hot Module Replacement enabled.",
19+
"[webpack-dev-server] Live Reloading enabled.",
20+
]
21+
`;
22+
23+
exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = `
24+
Array [
25+
"[HMR] Waiting for update signal from WDS...",
26+
"two",
27+
"[webpack-dev-server] Hot Module Replacement enabled.",
28+
"[webpack-dev-server] Live Reloading enabled.",
29+
]
30+
`;
31+
32+
exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`;
33+
34+
exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`;
35+
36+
exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = `
37+
Array [
38+
"[HMR] Waiting for update signal from WDS...",
39+
"one",
40+
"[webpack-dev-server] Hot Module Replacement enabled.",
41+
]
42+
`;
43+
44+
exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = `
45+
Array [
46+
"[HMR] Waiting for update signal from WDS...",
47+
"two",
48+
"[webpack-dev-server] Hot Module Replacement enabled.",
49+
]
50+
`;
51+
52+
exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`;
53+
54+
exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`;
55+
56+
exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = `
57+
Array [
58+
"one",
59+
"[webpack-dev-server] Live Reloading enabled.",
60+
]
61+
`;
62+
63+
exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = `
64+
Array [
65+
"two",
66+
"[webpack-dev-server] Live Reloading enabled.",
67+
]
68+
`;
69+
70+
exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`;
71+
72+
exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`;
73+
74+
exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = `
75+
Array [
76+
"[HMR] Waiting for update signal from WDS...",
77+
"Hello from the browser",
78+
"[webpack-dev-server] Hot Module Replacement enabled.",
79+
"[webpack-dev-server] Live Reloading enabled.",
80+
]
81+
`;
82+
83+
exports[`multi compiler should work with universal configurations with hot and live reload: page errors 1`] = `Array []`;
84+
85+
exports[`multi compiler should work with universal configurations with only hot reload: console messages 1`] = `
86+
Array [
87+
"[HMR] Waiting for update signal from WDS...",
88+
"Hello from the browser",
89+
"[webpack-dev-server] Hot Module Replacement enabled.",
90+
]
91+
`;
92+
93+
exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`;
94+
95+
exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = `
96+
Array [
97+
"Hello from the browser",
98+
"[webpack-dev-server] Live Reloading enabled.",
99+
]
100+
`;
101+
102+
exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

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

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

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

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

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

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

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

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

test/e2e/module-federation.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const objectEntryConfig = require("../fixtures/module-federation-config/webpack.
88
const multiConfig = require("../fixtures/module-federation-config/webpack.multi.config");
99
const runBrowser = require("../helpers/run-browser");
1010
const isWebpack5 = require("../helpers/isWebpack5");
11-
const port = require("../ports-map")["universal-compiler"];
11+
const port = require("../ports-map")["module-federation"];
1212

1313
const describeOnlyWebpack5 = isWebpack5 ? describe : describe.skip;
1414

0 commit comments

Comments
 (0)