Skip to content

Commit 887852f

Browse files
committed
Allow to share hotUpdateCallback
fixes webpack#423
1 parent 1bc0b8c commit 887852f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/HotModuleReplacementPlugin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ var hotInitCode = Template.getFunctionContent(function() {
318318
var hotWaitingFiles = 0;
319319
var hotChunksLoading = 0;
320320
var hotWaitingFilesMap = {};
321+
var hotRequestedFilesMap = {};
321322
var hotAvailibleFilesMap = {};
322323
var hotCallback;
323324

@@ -336,6 +337,7 @@ var hotInitCode = Template.getFunctionContent(function() {
336337
return;
337338
}
338339

340+
hotRequestedFilesMap = {};
339341
hotAvailibleFilesMap = {};
340342
hotWaitingFilesMap = {};
341343
for(var i = 0; i < update.c.length; i++)
@@ -355,6 +357,9 @@ var hotInitCode = Template.getFunctionContent(function() {
355357
}
356358

357359
function hotAddUpdateChunk(chunkId, moreModules) {
360+
if(!hotAvailibleFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
361+
return;
362+
hotRequestedFilesMap[chunkId] = false;
358363
for(var moduleId in moreModules) {
359364
hotUpdate[moduleId] = moreModules[moduleId];
360365
}
@@ -367,6 +372,7 @@ var hotInitCode = Template.getFunctionContent(function() {
367372
if(!hotAvailibleFilesMap[chunkId]) {
368373
hotWaitingFilesMap[chunkId] = true;
369374
} else {
375+
hotRequestedFilesMap[chunkId] = true;
370376
hotWaitingFiles++;
371377
hotDownloadUpdateChunk(chunkId);
372378
}

lib/JsonpMainTemplatePlugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
120120
.replace(Template.REGEXP_ID, "\" + chunkId + \"");
121121
var currentHotUpdateMainFilename = JSON.stringify(hotUpdateMainFilename)
122122
.replace(Template.REGEXP_HASH, "\" + " + this.renderCurrentHashCode(hash) + " + \"");
123-
return source + "\nthis[" + JSON.stringify(hotUpdateFunction) + "] = " + Template.getFunctionContent(function() {
123+
return source + "\n"+
124+
"var parentHotUpdateCallback = this[" + JSON.stringify(hotUpdateFunction) + "];\n" +
125+
"this[" + JSON.stringify(hotUpdateFunction) + "] = " + Template.getFunctionContent(function() {
124126
function webpackHotUpdateCallback(chunkId, moreModules) {
125127
hotAddUpdateChunk(chunkId, moreModules);
128+
if(parentHotUpdateCallback) parentHotUpdateCallback(chunkId, moreModules);
126129
}
127130

128131
function hotDownloadUpdateChunk(chunkId) {

0 commit comments

Comments
 (0)