Skip to content

Commit 2e5fc25

Browse files
committed
fixed some bugs webpack#26
1 parent d8fc847 commit 2e5fc25

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎lib/HotModuleReplacementPlugin.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ var hotInitCode = function() {
177177

178178
function hotUpdateDownloaded() {
179179
var outdatedDependencies = hotUpdateOutdatedDependencies = {};
180-
var outdatedModules = hotUpdateOutdatedModules = Object.keys(hotUpdate).slice();
180+
var outdatedModules = hotUpdateOutdatedModules = Object.keys(hotUpdate).map(function(id) {
181+
return +id;
182+
});
181183
var queue = outdatedModules.slice();
182184
while(queue.length > 0) {
183185
var moduleId = queue.pop();
184186
var module = installedModules[moduleId];
185-
if(module.hot._selfAccepted)
187+
if(!module || module.hot._selfAccepted)
186188
continue;
187189
if(module.hot._selfDeclined) {
188190
hotSetStatus("abort");
@@ -322,8 +324,9 @@ var hotInitCode = function() {
322324
var hotWaitingFilesMap = {};
323325
var hotCallback;
324326
function hotCheck(callback) {
327+
callback = callback || function(err) { if(err) throw err };
325328
if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
326-
if(typeof XMLHttpRequest === "undefined" || !Array.prototype.forEach || !Object.keys)
329+
if(typeof XMLHttpRequest === "undefined" || !Array.prototype.forEach || !Array.prototype.map || !Object.keys)
327330
return callback(new Error("No browser support"));
328331
hotSetStatus("check");
329332

@@ -346,7 +349,7 @@ var hotInitCode = function() {
346349

347350
hotWaitingFilesMap = {};
348351
hotSetStatus("prepare");
349-
hotCallback = callback || function(err) { if(err) throw err };
352+
hotCallback = callback;
350353
hotUpdate = {};
351354
var hash = hotCurrentHash;
352355
/*foreachInstalledChunks*/ {
@@ -373,22 +376,23 @@ var hotInitCode = function() {
373376
var outdatedModules = hotUpdateOutdatedModules;
374377
var outdatedDependencies = hotUpdateOutdatedDependencies;
375378
var outdatedSelfAcceptedModules = outdatedModules.filter(function(moduleId) {
376-
return installedModules[moduleId].hot._selfAccepted;
379+
return installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted;
377380
});
378381

379382
hotSetStatus("dispose");
380383
var oldModulesData = {};
381384
outdatedModules.forEach(function(moduleId) {
382385
var data = {};
383386
var module = installedModules[moduleId];
387+
if(!module) return;
384388
module.hot._disposeHandlers.forEach(function(cb) {
385389
cb(data);
386390
});
387391
oldModulesData[moduleId] = data;
388-
return
389392
}, this);
390393
outdatedModules.forEach(function(moduleId) {
391394
var module = installedModules[moduleId];
395+
if(!module) return;
392396
delete installedModules[moduleId];
393397
module.children.forEach(function(child) {
394398
child = installedModules[child];

‎test/hotPlayground/applyStyle2.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This file can update, because it accept itself.
2+
// A dispose handler removes the old <style> element.
3+
4+
require("bundle!./style2.js");

‎test/hotPlayground/index.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ window.onload = function() {
3838

3939
require("./style.js");
4040

41-
require("bundle!./style2.js");
41+
require("./applyStyle2");
4242

4343
if(module.hot) {
4444

@@ -54,5 +54,9 @@ window.onload = function() {
5454
document.body.appendChild(element2);
5555
});
5656

57+
module.hot.accept("./applyStyle2", function() {
58+
require("./applyStyle2");
59+
});
60+
5761
}
5862
};

0 commit comments

Comments
 (0)