Skip to content

Commit

Permalink
Merge pull request #15859 from donalffons/main
Browse files Browse the repository at this point in the history
Fix "window is not defined" when using HMR on worker
  • Loading branch information
sokra committed Nov 9, 2022
2 parents a8d7922 + a4b95c8 commit aa560ad
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions hot/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ if (module.hot) {
.check(true)
.then(function (updatedModules) {
if (!updatedModules) {
log("warning", "[HMR] Cannot find update. Need to do a full reload!");
log(
"warning",
"[HMR] Cannot find update. " +
(typeof window !== "undefined"
? "Need to do a full reload!"
: "Please reload manually!")
);
log(
"warning",
"[HMR] (Probably because of restarting the webpack-dev-server)"
);
window.location.reload();
if (typeof window !== "undefined") {
window.location.reload();
}
return;
}

Expand All @@ -38,10 +46,15 @@ if (module.hot) {
if (["abort", "fail"].indexOf(status) >= 0) {
log(
"warning",
"[HMR] Cannot apply update. Need to do a full reload!"
"[HMR] Cannot apply update. " +
(typeof window !== "undefined"
? "Need to do a full reload!"
: "Please reload manually!")
);
log("warning", "[HMR] " + log.formatError(err));
window.location.reload();
if (typeof window !== "undefined") {
window.location.reload();
}
} else {
log("warning", "[HMR] Update failed: " + log.formatError(err));
}
Expand Down

0 comments on commit aa560ad

Please sign in to comment.