diff --git a/lib/HotModuleReplacementPlugin.js b/lib/HotModuleReplacementPlugin.js index d9a5ad5c0..e56af1a6a 100644 --- a/lib/HotModuleReplacementPlugin.js +++ b/lib/HotModuleReplacementPlugin.js @@ -177,12 +177,14 @@ var hotInitCode = function() { function hotUpdateDownloaded() { var outdatedDependencies = hotUpdateOutdatedDependencies = {}; - var outdatedModules = hotUpdateOutdatedModules = Object.keys(hotUpdate).slice(); + var outdatedModules = hotUpdateOutdatedModules = Object.keys(hotUpdate).map(function(id) { + return +id; + }); var queue = outdatedModules.slice(); while(queue.length > 0) { var moduleId = queue.pop(); var module = installedModules[moduleId]; - if(module.hot._selfAccepted) + if(!module || module.hot._selfAccepted) continue; if(module.hot._selfDeclined) { hotSetStatus("abort"); @@ -322,8 +324,9 @@ var hotInitCode = function() { var hotWaitingFilesMap = {}; var hotCallback; function hotCheck(callback) { + callback = callback || function(err) { if(err) throw err }; if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status"); - if(typeof XMLHttpRequest === "undefined" || !Array.prototype.forEach || !Object.keys) + if(typeof XMLHttpRequest === "undefined" || !Array.prototype.forEach || !Array.prototype.map || !Object.keys) return callback(new Error("No browser support")); hotSetStatus("check"); @@ -346,7 +349,7 @@ var hotInitCode = function() { hotWaitingFilesMap = {}; hotSetStatus("prepare"); - hotCallback = callback || function(err) { if(err) throw err }; + hotCallback = callback; hotUpdate = {}; var hash = hotCurrentHash; /*foreachInstalledChunks*/ { @@ -373,7 +376,7 @@ var hotInitCode = function() { var outdatedModules = hotUpdateOutdatedModules; var outdatedDependencies = hotUpdateOutdatedDependencies; var outdatedSelfAcceptedModules = outdatedModules.filter(function(moduleId) { - return installedModules[moduleId].hot._selfAccepted; + return installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted; }); hotSetStatus("dispose"); @@ -381,14 +384,15 @@ var hotInitCode = function() { outdatedModules.forEach(function(moduleId) { var data = {}; var module = installedModules[moduleId]; + if(!module) return; module.hot._disposeHandlers.forEach(function(cb) { cb(data); }); oldModulesData[moduleId] = data; - return }, this); outdatedModules.forEach(function(moduleId) { var module = installedModules[moduleId]; + if(!module) return; delete installedModules[moduleId]; module.children.forEach(function(child) { child = installedModules[child]; diff --git a/test/hotPlayground/applyStyle2.js b/test/hotPlayground/applyStyle2.js new file mode 100644 index 000000000..124e82df7 --- /dev/null +++ b/test/hotPlayground/applyStyle2.js @@ -0,0 +1,4 @@ +// This file can update, because it accept itself. +// A dispose handler removes the old