Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #5500 from webpack/bugfix/hmr-disposed-handler
avoid calling accept handler on disposed modules
  • Loading branch information
sokra committed Aug 11, 2017
2 parents 0110035 + d8a05cf commit f7bcba7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
53 changes: 30 additions & 23 deletions lib/HotModuleReplacement.runtime.js
Expand Up @@ -462,6 +462,9 @@ module.exports = function() {
// remove module from cache
delete installedModules[moduleId];

// when disposing there is no need to call dispose handler
delete outdatedDependencies[moduleId];

// remove "parents" references from all children
for(j = 0; j < module.children.length; j++) {
var child = installedModules[module.children[j]];
Expand Down Expand Up @@ -507,30 +510,34 @@ module.exports = function() {
for(moduleId in outdatedDependencies) {
if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
module = installedModules[moduleId];
moduleOutdatedDependencies = outdatedDependencies[moduleId];
var callbacks = [];
for(i = 0; i < moduleOutdatedDependencies.length; i++) {
dependency = moduleOutdatedDependencies[i];
cb = module.hot._acceptedDependencies[dependency];
if(callbacks.indexOf(cb) >= 0) continue;
callbacks.push(cb);
}
for(i = 0; i < callbacks.length; i++) {
cb = callbacks[i];
try {
cb(moduleOutdatedDependencies);
} catch(err) {
if(options.onErrored) {
options.onErrored({
type: "accept-errored",
moduleId: moduleId,
dependencyId: moduleOutdatedDependencies[i],
error: err
});
if(module) {
moduleOutdatedDependencies = outdatedDependencies[moduleId];
var callbacks = [];
for(i = 0; i < moduleOutdatedDependencies.length; i++) {
dependency = moduleOutdatedDependencies[i];
cb = module.hot._acceptedDependencies[dependency];
if(cb) {
if(callbacks.indexOf(cb) >= 0) continue;
callbacks.push(cb);
}
if(!options.ignoreErrored) {
if(!error)
error = err;
}
for(i = 0; i < callbacks.length; i++) {
cb = callbacks[i];
try {
cb(moduleOutdatedDependencies);
} catch(err) {
if(options.onErrored) {
options.onErrored({
type: "accept-errored",
moduleId: moduleId,
dependencyId: moduleOutdatedDependencies[i],
error: err
});
}
if(!options.ignoreErrored) {
if(!error)
error = err;
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/hotCases/runtime/circular/a.js
@@ -0,0 +1,7 @@
import "./";
import "./b";
export default 1;
---
import "./";
import "./b";
export default 2;
5 changes: 5 additions & 0 deletions test/hotCases/runtime/circular/b.js
@@ -0,0 +1,5 @@
import "./a";
export default 1;
module.hot.accept("./a");
---
export default 2;
10 changes: 10 additions & 0 deletions test/hotCases/runtime/circular/index.js
@@ -0,0 +1,10 @@
import a from "./a";

it("should not throw on circular dependencies", function(done) {
a.should.be.eql(1);
module.hot.accept("./a", function() {
a.should.be.eql(2);
done();
});
NEXT(require("../../update")(done));
});

0 comments on commit f7bcba7

Please sign in to comment.