Skip to content

Commit

Permalink
fix: reloading logic for multi compiler mode (#3841)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 13, 2021
1 parent e019bd2 commit ef148ec
Show file tree
Hide file tree
Showing 6 changed files with 857 additions and 97 deletions.
1 change: 1 addition & 0 deletions client-src/index.js
Expand Up @@ -87,6 +87,7 @@ const onSocketMessage = {
sendMessage("Invalid");
},
hash(hash) {
status.previousHash = status.currentHash;
status.currentHash = hash;
},
logging: setAllLogLevel,
Expand Down
17 changes: 2 additions & 15 deletions client-src/utils/reloadApp.js
Expand Up @@ -8,23 +8,10 @@ function reloadApp({ hot, liveReload }, status) {
return;
}

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

if (isInitial) {
const isLegacyInitial =
webpackHash === "" && hot === false && liveReload === true;

if (isLegacyInitial) {
status.previousHash = status.currentHash;
}

return;
}

Expand Down
229 changes: 202 additions & 27 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 one web target configuration: console messages 1`] = `
exports[`multi compiler should work with one web target configuration and do nothing: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
Expand All @@ -9,94 +9,269 @@ Array [
]
`;

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

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = `
exports[`multi compiler should work with universal configuration and do nothing: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"Hello from the browser",
"[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`] = `
exports[`multi compiler should work with universal configuration and do nothing: page errors 1`] = `Array []`;

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`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App hot update...",
"[HMR] Checking for updates on the server...",
"[HMR] Cannot apply update. Need to do a full reload!",
"[HMR] Error: Aborted because ./browser.js is not accepted
Update propagation: ./browser.js -> 0
<stack>",
"[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 two web target configurations with hot and live reload: page errors 1`] = `Array []`;
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 []`;

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 universal configuration when only hot reload is enabled, and do hot reload for browser compiler when browser entry changed: 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] App updated. Recompiling...",
"[webpack-dev-server] App hot update...",
"[HMR] Checking for updates on the server...",
"[HMR] Cannot apply update. Need to do a full reload!",
"[HMR] Error: Aborted because ./browser.js is not accepted
Update propagation: ./browser.js -> 0
at hotApplyInternal (http://127.0.0.1:8103/browser.js:508:30)
at hotApply (http://127.0.0.1:8103/browser.js:362:19)
at http://127.0.0.1:8103/browser.js:337:22",
"[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 configuration when only hot reload is enabled, and do hot reload for browser compiler when browser entry changed: page errors 1`] = `Array []`;

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`] = `
Array [
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App updated. Reloading...",
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = `
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`] = `
Array [
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App updated. Reloading...",
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

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 []`;

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 []`;

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`] = `
Array [
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App updated. Reloading...",
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

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`] = `
Array [
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App updated. Reloading...",
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

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 []`;

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 []`;

exports[`multi compiler should work with web target configurations and do nothing: 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 only hot reload: console messages 2`] = `
exports[`multi compiler should work with web target configurations and do nothing: 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 only hot reload: page errors 1`] = `Array []`;
exports[`multi compiler should work with web target configurations and do nothing: 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 web target configurations and do nothing: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = `
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`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App hot update...",
"[HMR] Checking for updates on the server...",
"[HMR] Cannot apply update. Need to do a full reload!",
"[HMR] Error: Aborted because ./one.js is not accepted
Update propagation: ./one.js -> 0
<stack>",
"[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 only live reload: console messages 2`] = `
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`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App hot update...",
"[HMR] Checking for updates on the server...",
"[HMR] Cannot apply update. Need to do a full reload!",
"[HMR] Error: Aborted because ./two.js is not accepted
Update propagation: ./two.js -> 0
<stack>",
"[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 only live reload: page errors 1`] = `Array []`;
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 []`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`;
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 []`;

exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = `
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`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App hot update...",
"[HMR] Checking for updates on the server...",
"[HMR] Cannot apply update. Need to do a full reload!",
"[HMR] Error: Aborted because ./one.js is not accepted
Update propagation: ./one.js -> 0
<stack>",
"[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 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`] = `
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`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App hot update...",
"[HMR] Checking for updates on the server...",
"[HMR] Cannot apply update. Need to do a full reload!",
"[HMR] Error: Aborted because ./two.js is not accepted
Update propagation: ./two.js -> 0
<stack>",
"[HMR] Waiting for update signal from WDS...",
"two",
"[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 web target configurations when only hot reload is enabled, and do hot reload when changing own entries: page errors 1`] = `Array []`;

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 []`;

exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = `
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`] = `
Array [
"Hello from the browser",
"one",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App updated. Reloading...",
"one",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

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`] = `
Array [
"two",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App updated. Reloading...",
"two",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

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 []`;

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 []`;

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`] = `
Array [
"one",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App updated. Reloading...",
"one",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

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`] = `
Array [
"two",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] App updated. Recompiling...",
"[webpack-dev-server] App updated. Reloading...",
"two",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`;
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 []`;

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 comments on commit ef148ec

Please sign in to comment.