Skip to content

Commit

Permalink
Merge pull request #9202 from webpack/bugfix/9198
Browse files Browse the repository at this point in the history
fix rejection when removing and readding self-accepted module
  • Loading branch information
sokra committed May 29, 2019
2 parents 671cb18 + 46b428b commit c408ff5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/HotModuleReplacement.runtime.js
Expand Up @@ -290,7 +290,7 @@ module.exports = function() {
var outdatedModules = [updateModuleId];
var outdatedDependencies = {};

var queue = outdatedModules.slice().map(function(id) {
var queue = outdatedModules.map(function(id) {
return {
chain: [id],
id: id
Expand Down Expand Up @@ -467,12 +467,15 @@ module.exports = function() {
moduleId = outdatedModules[i];
if (
installedModules[moduleId] &&
installedModules[moduleId].hot._selfAccepted
)
installedModules[moduleId].hot._selfAccepted &&
// removed self-accepted modules should not be required
appliedUpdate[moduleId] !== warnUnexpectedRequire
) {
outdatedSelfAcceptedModules.push({
module: moduleId,
errorHandler: installedModules[moduleId].hot._selfAccepted
});
}
}

// Now in "dispose" phase
Expand Down Expand Up @@ -539,7 +542,7 @@ module.exports = function() {
}
}

// Not in "apply" phase
// Now in "apply" phase
hotSetStatus("apply");

hotCurrentHash = hotUpdateNewHash;
Expand Down
20 changes: 20 additions & 0 deletions test/hotCases/recover/recover-after-removal-self-accepted/index.js
@@ -0,0 +1,20 @@
import ok from "./module";

it("should abort when module is not accepted", done => {
expect(ok).toBe("ok1-inner");
NEXT(
require("../../update")(done, true, () => {
expect(ok).toBe("ok2");
NEXT(
require("../../update")(done, true, () => {
expect(ok).toBe("ok3-inner");
done();
})
);
})
);
});

if (module.hot) {
module.hot.accept("./module");
}
@@ -0,0 +1,3 @@
module.hot.accept();

export default "-inner";
@@ -0,0 +1,9 @@
import inner from "./inner";

export default "ok1" + inner;
---
export default "ok2";
---
import inner from "./inner";

export default "ok3" + inner;

0 comments on commit c408ff5

Please sign in to comment.