fix: hotUpdate chunk modified with new runtime should have correct runtime

This commit is contained in:
Alexander Akait 2024-10-30 17:29:43 +03:00 committed by GitHub
commit bea6384038
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 52 additions and 1 deletions

View File

@ -686,7 +686,9 @@ class HotModuleReplacementPlugin {
if (backCompat)
ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph);
hotUpdateChunk.id = chunkId;
hotUpdateChunk.runtime = newRuntime;
hotUpdateChunk.runtime = currentChunk
? currentChunk.runtime
: newRuntime;
if (currentChunk) {
for (const group of currentChunk.groupsIterable)
hotUpdateChunk.addGroup(group);

View File

@ -0,0 +1,13 @@
let value = require("./module.js");
import {a} from "./lib/a.js";
it("should compile", (done) => {
expect(value).toBe(1);
expect(a).toBe(1);
module.hot.accept("./module.js", () => {
value = require("./module");
expect(value).toBe(2);
done();
});
NEXT(require("../../update")(done));
});

View File

@ -0,0 +1 @@
export const a = 1

View File

@ -0,0 +1 @@
export const b = 1

View File

@ -0,0 +1,3 @@
{
"sideEffects": true
}

View File

@ -0,0 +1,4 @@
module.exports = 1;
---
new Worker(new URL('./worker.js', import.meta.url))
module.exports = 2;

View File

@ -0,0 +1,8 @@
var supportsWorker = require("../../../helpers/supportsWorker");
module.exports = function (config) {
if (config.target !== "web") {
return false;
}
return supportsWorker();
};

View File

@ -0,0 +1,17 @@
module.exports = {
optimization: {
usedExports: true,
// make 'lib' chunk runtime to be worker + entry
splitChunks: {
minSize: 0,
chunks: "all",
cacheGroups: {
lib: {
test: /[/\\]lib[/\\](a|b|index).js$/,
name: "lib",
filename: "bundle-lib.js"
}
}
}
}
};

View File

@ -0,0 +1,2 @@
import {b} from "./lib/b.js";
b;