Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reloading on failed update in webpack 5 #394

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions process-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,6 @@ var hmrDocsUrl = 'https://webpack.js.org/concepts/hot-module-replacement/'; // e

var lastHash;
var failureStatuses = { abort: 1, fail: 1 };
var applyOptions = {
ignoreUnaccepted: true,
ignoreDeclined: true,
ignoreErrored: true,
onUnaccepted: function(data) {
console.warn(
'Ignored an update to unaccepted module ' + data.chain.join(' -> ')
);
},
onDeclined: function(data) {
console.warn(
'Ignored an update to declined module ' + data.chain.join(' -> ')
);
},
onErrored: function(data) {
console.error(data.error);
console.warn(
'Ignored an error while updating module ' +
data.moduleId +
' (' +
data.type +
')'
);
},
};

function upToDate(hash) {
if (hash) lastHash = hash;
Expand All @@ -65,12 +40,44 @@ module.exports = function(hash, moduleMap, options) {
return null;
}

var failedUpdate = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failedUpdate is false here then how it will get changed to true again when the update gets failed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 62, 68, 79 in the new coe.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood Thank you

var applyCallback = function(applyErr, renewedModules) {
if (applyErr) return handleError(applyErr);

if (!upToDate()) check();

logUpdates(updatedModules, renewedModules);
if (failedUpdate) {
performReload();
}
};
var applyOptions = {
ignoreUnaccepted: true,
ignoreDeclined: true,
ignoreErrored: true,
onUnaccepted: function(data) {
console.warn(
'Ignored an update to unaccepted module ' + data.chain.join(' -> ')
);
failedUpdate = true;
},
onDeclined: function(data) {
console.warn(
'Ignored an update to declined module ' + data.chain.join(' -> ')
);
failedUpdate = true;
},
onErrored: function(data) {
console.error(data.error);
console.warn(
'Ignored an error while updating module ' +
data.moduleId +
' (' +
data.type +
')'
);
failedUpdate = true;
},
};

var applyResult = module.hot.apply(applyOptions, applyCallback);
Expand Down