Skip to content

Commit ef148ec

Browse files
fix: reloading logic for multi compiler mode (#3841)
1 parent e019bd2 commit ef148ec

File tree

6 files changed

+857
-97
lines changed

6 files changed

+857
-97
lines changed

client-src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const onSocketMessage = {
8787
sendMessage("Invalid");
8888
},
8989
hash(hash) {
90+
status.previousHash = status.currentHash;
9091
status.currentHash = hash;
9192
},
9293
logging: setAllLogLevel,

client-src/utils/reloadApp.js

+2-15
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,10 @@ function reloadApp({ hot, liveReload }, status) {
88
return;
99
}
1010

11-
// TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement plugin
12-
const webpackHash =
13-
// eslint-disable-next-line camelcase
14-
typeof __webpack_hash__ !== "undefined"
15-
? // eslint-disable-next-line camelcase
16-
__webpack_hash__
17-
: status.previousHash || "";
18-
const isInitial = status.currentHash.indexOf(webpackHash) >= 0;
11+
const { currentHash, previousHash } = status;
12+
const isInitial = currentHash.indexOf(previousHash) >= 0;
1913

2014
if (isInitial) {
21-
const isLegacyInitial =
22-
webpackHash === "" && hot === false && liveReload === true;
23-
24-
if (isLegacyInitial) {
25-
status.previousHash = status.currentHash;
26-
}
27-
2815
return;
2916
}
3017

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 one web target configuration: console messages 1`] = `
3+
exports[`multi compiler should work with one web target configuration and do nothing: console messages 1`] = `
44
Array [
55
"[HMR] Waiting for update signal from WDS...",
66
"Hey.",
@@ -9,94 +9,269 @@ Array [
99
]
1010
`;
1111

12-
exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`;
12+
exports[`multi compiler should work with one web target configuration and do nothing: page errors 1`] = `Array []`;
1313

14-
exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = `
14+
exports[`multi compiler should work with universal configuration and do nothing: console messages 1`] = `
1515
Array [
1616
"[HMR] Waiting for update signal from WDS...",
17-
"one",
17+
"Hello from the browser",
1818
"[webpack-dev-server] Hot Module Replacement enabled.",
1919
"[webpack-dev-server] Live Reloading enabled.",
2020
]
2121
`;
2222

23-
exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = `
23+
exports[`multi compiler should work with universal configuration and do nothing: page errors 1`] = `Array []`;
24+
25+
exports[`multi compiler should work with universal configuration when hot and live reloads are enabled, and do hot reload for browser compiler by default when browser entry changed: console messages 1`] = `
2426
Array [
2527
"[HMR] Waiting for update signal from WDS...",
26-
"two",
28+
"Hello from the browser",
29+
"[webpack-dev-server] Hot Module Replacement enabled.",
30+
"[webpack-dev-server] Live Reloading enabled.",
31+
"[webpack-dev-server] App updated. Recompiling...",
32+
"[webpack-dev-server] App hot update...",
33+
"[HMR] Checking for updates on the server...",
34+
"[HMR] Cannot apply update. Need to do a full reload!",
35+
"[HMR] Error: Aborted because ./browser.js is not accepted
36+
Update propagation: ./browser.js -> 0
37+
<stack>",
38+
"[HMR] Waiting for update signal from WDS...",
39+
"Hello from the browser",
2740
"[webpack-dev-server] Hot Module Replacement enabled.",
2841
"[webpack-dev-server] Live Reloading enabled.",
2942
]
3043
`;
3144

32-
exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`;
45+
exports[`multi compiler should work with universal configuration when hot and live reloads are enabled, and do hot reload for browser compiler by default when browser entry changed: page errors 1`] = `Array []`;
3346

34-
exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`;
47+
exports[`multi compiler should work with universal configuration when only hot reload is enabled, and do hot reload for browser compiler when browser entry changed: console messages 1`] = `
48+
Array [
49+
"[HMR] Waiting for update signal from WDS...",
50+
"Hello from the browser",
51+
"[webpack-dev-server] Hot Module Replacement enabled.",
52+
"[webpack-dev-server] App updated. Recompiling...",
53+
"[webpack-dev-server] App hot update...",
54+
"[HMR] Checking for updates on the server...",
55+
"[HMR] Cannot apply update. Need to do a full reload!",
56+
"[HMR] Error: Aborted because ./browser.js is not accepted
57+
Update propagation: ./browser.js -> 0
58+
at hotApplyInternal (http://127.0.0.1:8103/browser.js:508:30)
59+
at hotApply (http://127.0.0.1:8103/browser.js:362:19)
60+
at http://127.0.0.1:8103/browser.js:337:22",
61+
"[HMR] Waiting for update signal from WDS...",
62+
"Hello from the browser",
63+
"[webpack-dev-server] Hot Module Replacement enabled.",
64+
]
65+
`;
66+
67+
exports[`multi compiler should work with universal configuration when only hot reload is enabled, and do hot reload for browser compiler when browser entry changed: page errors 1`] = `Array []`;
68+
69+
exports[`multi compiler should work with universal configuration when only live reload is enabled, and do live reload for browser compiler when changing browser and server entries: console messages 1`] = `
70+
Array [
71+
"Hello from the browser",
72+
"[webpack-dev-server] Live Reloading enabled.",
73+
"[webpack-dev-server] App updated. Recompiling...",
74+
"[webpack-dev-server] App updated. Reloading...",
75+
"Hello from the browser",
76+
"[webpack-dev-server] Live Reloading enabled.",
77+
]
78+
`;
3579

36-
exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = `
80+
exports[`multi compiler should work with universal configuration when only live reload is enabled, and do live reload for browser compiler when changing browser and server entries: console messages 2`] = `
81+
Array [
82+
"Hello from the browser",
83+
"[webpack-dev-server] Live Reloading enabled.",
84+
"[webpack-dev-server] App updated. Recompiling...",
85+
"[webpack-dev-server] App updated. Reloading...",
86+
"Hello from the browser",
87+
"[webpack-dev-server] Live Reloading enabled.",
88+
]
89+
`;
90+
91+
exports[`multi compiler should work with universal configuration when only live reload is enabled, and do live reload for browser compiler when changing browser and server entries: page errors 1`] = `Array []`;
92+
93+
exports[`multi compiler should work with universal configuration when only live reload is enabled, and do live reload for browser compiler when changing browser and server entries: page errors 2`] = `Array []`;
94+
95+
exports[`multi compiler should work with universal configuration when only live reload is enabled, and do live reload for browser compiler when changing server and browser entries: console messages 1`] = `
96+
Array [
97+
"Hello from the browser",
98+
"[webpack-dev-server] Live Reloading enabled.",
99+
"[webpack-dev-server] App updated. Recompiling...",
100+
"[webpack-dev-server] App updated. Reloading...",
101+
"Hello from the browser",
102+
"[webpack-dev-server] Live Reloading enabled.",
103+
]
104+
`;
105+
106+
exports[`multi compiler should work with universal configuration when only live reload is enabled, and do live reload for browser compiler when changing server and browser entries: console messages 2`] = `
107+
Array [
108+
"Hello from the browser",
109+
"[webpack-dev-server] Live Reloading enabled.",
110+
"[webpack-dev-server] App updated. Recompiling...",
111+
"[webpack-dev-server] App updated. Reloading...",
112+
"Hello from the browser",
113+
"[webpack-dev-server] Live Reloading enabled.",
114+
]
115+
`;
116+
117+
exports[`multi compiler should work with universal configuration when only live reload is enabled, and do live reload for browser compiler when changing server and browser entries: page errors 1`] = `Array []`;
118+
119+
exports[`multi compiler should work with universal configuration when only live reload is enabled, and do live reload for browser compiler when changing server and browser entries: page errors 2`] = `Array []`;
120+
121+
exports[`multi compiler should work with web target configurations and do nothing: console messages 1`] = `
37122
Array [
38123
"[HMR] Waiting for update signal from WDS...",
39124
"one",
40125
"[webpack-dev-server] Hot Module Replacement enabled.",
126+
"[webpack-dev-server] Live Reloading enabled.",
41127
]
42128
`;
43129

44-
exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = `
130+
exports[`multi compiler should work with web target configurations and do nothing: console messages 2`] = `
45131
Array [
46132
"[HMR] Waiting for update signal from WDS...",
47133
"two",
48134
"[webpack-dev-server] Hot Module Replacement enabled.",
135+
"[webpack-dev-server] Live Reloading enabled.",
49136
]
50137
`;
51138

52-
exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`;
139+
exports[`multi compiler should work with web target configurations and do nothing: page errors 1`] = `Array []`;
53140

54-
exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`;
141+
exports[`multi compiler should work with web target configurations and do nothing: page errors 2`] = `Array []`;
55142

56-
exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = `
143+
exports[`multi compiler should work with web target configurations when hot and live reloads are enabled, and do hot reload by default when changing own entries: console messages 1`] = `
57144
Array [
145+
"[HMR] Waiting for update signal from WDS...",
58146
"one",
147+
"[webpack-dev-server] Hot Module Replacement enabled.",
148+
"[webpack-dev-server] Live Reloading enabled.",
149+
"[webpack-dev-server] App updated. Recompiling...",
150+
"[webpack-dev-server] App hot update...",
151+
"[HMR] Checking for updates on the server...",
152+
"[HMR] Cannot apply update. Need to do a full reload!",
153+
"[HMR] Error: Aborted because ./one.js is not accepted
154+
Update propagation: ./one.js -> 0
155+
<stack>",
156+
"[HMR] Waiting for update signal from WDS...",
157+
"one",
158+
"[webpack-dev-server] Hot Module Replacement enabled.",
59159
"[webpack-dev-server] Live Reloading enabled.",
60160
]
61161
`;
62162

63-
exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = `
163+
exports[`multi compiler should work with web target configurations when hot and live reloads are enabled, and do hot reload by default when changing own entries: console messages 2`] = `
64164
Array [
165+
"[HMR] Waiting for update signal from WDS...",
65166
"two",
167+
"[webpack-dev-server] Hot Module Replacement enabled.",
168+
"[webpack-dev-server] Live Reloading enabled.",
169+
"[webpack-dev-server] App updated. Recompiling...",
170+
"[webpack-dev-server] App hot update...",
171+
"[HMR] Checking for updates on the server...",
172+
"[HMR] Cannot apply update. Need to do a full reload!",
173+
"[HMR] Error: Aborted because ./two.js is not accepted
174+
Update propagation: ./two.js -> 0
175+
<stack>",
176+
"[HMR] Waiting for update signal from WDS...",
177+
"two",
178+
"[webpack-dev-server] Hot Module Replacement enabled.",
66179
"[webpack-dev-server] Live Reloading enabled.",
67180
]
68181
`;
69182

70-
exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`;
183+
exports[`multi compiler should work with web target configurations when hot and live reloads are enabled, and do hot reload by default when changing own entries: page errors 1`] = `Array []`;
71184

72-
exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`;
185+
exports[`multi compiler should work with web target configurations when hot and live reloads are enabled, and do hot reload by default when changing own entries: page errors 2`] = `Array []`;
73186

74-
exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = `
187+
exports[`multi compiler should work with web target configurations when only hot reload is enabled, and do hot reload when changing own entries: console messages 1`] = `
75188
Array [
76189
"[HMR] Waiting for update signal from WDS...",
77-
"Hello from the browser",
190+
"one",
191+
"[webpack-dev-server] Hot Module Replacement enabled.",
192+
"[webpack-dev-server] App updated. Recompiling...",
193+
"[webpack-dev-server] App hot update...",
194+
"[HMR] Checking for updates on the server...",
195+
"[HMR] Cannot apply update. Need to do a full reload!",
196+
"[HMR] Error: Aborted because ./one.js is not accepted
197+
Update propagation: ./one.js -> 0
198+
<stack>",
199+
"[HMR] Waiting for update signal from WDS...",
200+
"one",
78201
"[webpack-dev-server] Hot Module Replacement enabled.",
79-
"[webpack-dev-server] Live Reloading enabled.",
80202
]
81203
`;
82204

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`] = `
205+
exports[`multi compiler should work with web target configurations when only hot reload is enabled, and do hot reload when changing own entries: console messages 2`] = `
86206
Array [
87207
"[HMR] Waiting for update signal from WDS...",
88-
"Hello from the browser",
208+
"two",
209+
"[webpack-dev-server] Hot Module Replacement enabled.",
210+
"[webpack-dev-server] App updated. Recompiling...",
211+
"[webpack-dev-server] App hot update...",
212+
"[HMR] Checking for updates on the server...",
213+
"[HMR] Cannot apply update. Need to do a full reload!",
214+
"[HMR] Error: Aborted because ./two.js is not accepted
215+
Update propagation: ./two.js -> 0
216+
<stack>",
217+
"[HMR] Waiting for update signal from WDS...",
218+
"two",
89219
"[webpack-dev-server] Hot Module Replacement enabled.",
90220
]
91221
`;
92222

93-
exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`;
223+
exports[`multi compiler should work with web target configurations when only hot reload is enabled, and do hot reload when changing own entries: page errors 1`] = `Array []`;
224+
225+
exports[`multi compiler should work with web target configurations when only hot reload is enabled, and do hot reload when changing own entries: page errors 2`] = `Array []`;
94226

95-
exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = `
227+
exports[`multi compiler should work with web target configurations when only live reload is enabled and do live reload when changing other entries: console messages 1`] = `
96228
Array [
97-
"Hello from the browser",
229+
"one",
230+
"[webpack-dev-server] Live Reloading enabled.",
231+
"[webpack-dev-server] App updated. Recompiling...",
232+
"[webpack-dev-server] App updated. Reloading...",
233+
"one",
234+
"[webpack-dev-server] Live Reloading enabled.",
235+
]
236+
`;
237+
238+
exports[`multi compiler should work with web target configurations when only live reload is enabled and do live reload when changing other entries: console messages 2`] = `
239+
Array [
240+
"two",
241+
"[webpack-dev-server] Live Reloading enabled.",
242+
"[webpack-dev-server] App updated. Recompiling...",
243+
"[webpack-dev-server] App updated. Reloading...",
244+
"two",
245+
"[webpack-dev-server] Live Reloading enabled.",
246+
]
247+
`;
248+
249+
exports[`multi compiler should work with web target configurations when only live reload is enabled and do live reload when changing other entries: page errors 1`] = `Array []`;
250+
251+
exports[`multi compiler should work with web target configurations when only live reload is enabled and do live reload when changing other entries: page errors 2`] = `Array []`;
252+
253+
exports[`multi compiler should work with web target configurations when only live reload is enabled, and do live reload when changing own entries: console messages 1`] = `
254+
Array [
255+
"one",
256+
"[webpack-dev-server] Live Reloading enabled.",
257+
"[webpack-dev-server] App updated. Recompiling...",
258+
"[webpack-dev-server] App updated. Reloading...",
259+
"one",
260+
"[webpack-dev-server] Live Reloading enabled.",
261+
]
262+
`;
263+
264+
exports[`multi compiler should work with web target configurations when only live reload is enabled, and do live reload when changing own entries: console messages 2`] = `
265+
Array [
266+
"two",
267+
"[webpack-dev-server] Live Reloading enabled.",
268+
"[webpack-dev-server] App updated. Recompiling...",
269+
"[webpack-dev-server] App updated. Reloading...",
270+
"two",
98271
"[webpack-dev-server] Live Reloading enabled.",
99272
]
100273
`;
101274

102-
exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`;
275+
exports[`multi compiler should work with web target configurations when only live reload is enabled, and do live reload when changing own entries: page errors 1`] = `Array []`;
276+
277+
exports[`multi compiler should work with web target configurations when only live reload is enabled, and do live reload when changing own entries: page errors 2`] = `Array []`;

0 commit comments

Comments
 (0)