Merge pull request #10256 from webpack/bugfix/chunk-id-hmr

use correct string or number form of chunk id in HMR
This commit is contained in:
Tobias Koppers 2020-01-15 18:49:00 +01:00 committed by GitHub
commit fee4d37968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 70 additions and 1 deletions

View File

@ -308,12 +308,12 @@ class HotModuleReplacementPlugin {
};
const allRemovedModules = new Set();
for (const key of Object.keys(records.chunkHashs)) {
const chunkId = key;
const currentChunk = find(
compilation.chunks,
chunk => `${chunk.id}` === key
);
if (currentChunk) {
const chunkId = currentChunk.id;
const newModules = chunkGraph
.getChunkModules(currentChunk)
.filter(module => updatedModules.has(module));
@ -372,6 +372,7 @@ class HotModuleReplacementPlugin {
hotUpdateMainContent.c.push(chunkId);
}
} else {
const chunkId = `${+key}` === key ? +key : key;
hotUpdateMainContent.r.push(chunkId);
for (const id of records.chunkModuleIds[chunkId])
allRemovedModules.add(id);

View File

@ -0,0 +1 @@
export { value } from "./file";

View File

@ -0,0 +1,3 @@
import { value as v } from "./file";
export const value = v + 0.5;

View File

@ -0,0 +1,5 @@
export var value = 1;
---
export var value = 1.5;
---
export var value = 3;

View File

@ -0,0 +1,28 @@
import m from "./module";
it("should add and remove chunks", done => {
return m()
.then(chunk => {
expect(chunk.value).toBe(1);
let update = 0;
module.hot.accept("./module", () => {
m()
.then(chunk => {
switch (update) {
case 0:
expect(chunk.value).toBe(2);
break;
case 1:
expect(chunk.value).toBe(3);
done();
return;
}
update++;
NEXT(require("../../update")(done));
})
.catch(done);
});
NEXT(require("../../update")(done));
})
.catch(done);
});

View File

@ -0,0 +1,5 @@
export default () => import(/* webpackChunkName: "1e1" */ "./chunk");
---
export default () => import(/* webpackChunkName: "10" */ "./chunk2");
---
export default () => import(/* webpackChunkName: "1e1" */ "./chunk");

View File

@ -0,0 +1,3 @@
export var value = 1;
---
export var value = 2;

View File

@ -0,0 +1,15 @@
import { value } from "./file";
it("should auto-import an ES6 imported value on accept", function(done) {
expect(value).toBe(1);
module.hot.accept("./file", function() {
expect(value).toBe(2);
outside();
done();
});
NEXT(require("../../update")(done));
});
function outside() {
expect(value).toBe(2);
}

View File

@ -0,0 +1,8 @@
"use strict";
module.exports = {
mode: "production",
optimization: {
minimize: false
}
};