Skip to content

Commit 14582fc

Browse files
authored
Merge pull request #14684 from webpack/bugfix/cache-unaffected-module-id
fix a bug with experiments.cacheUnaffected
2 parents 86e3eb2 + 393fb6e commit 14582fc

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

lib/Compilation.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,9 +2424,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
24242424
let statNew = 0;
24252425
/**
24262426
* @param {Module} module module
2427-
* @returns {{ modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
2427+
* @returns {{ id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
24282428
*/
24292429
const computeReferences = module => {
2430+
const id = chunkGraph.getModuleId(module);
24302431
/** @type {Map<Module, string | number | undefined>} */
24312432
let modules = undefined;
24322433
/** @type {(string | number)[] | undefined} */
@@ -2454,16 +2455,18 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
24542455
queue.push.apply(queue, block.blocks);
24552456
}
24562457
}
2457-
return { modules, blocks };
2458+
return { id, modules, blocks };
24582459
};
24592460
/**
24602461
* @param {Module} module module
24612462
* @param {Object} references references
2463+
* @param {string | number} references.id id
24622464
* @param {Map<Module, string | number>=} references.modules modules
24632465
* @param {(string | number)[]=} references.blocks blocks
24642466
* @returns {boolean} ok?
24652467
*/
2466-
const compareReferences = (module, { modules, blocks }) => {
2468+
const compareReferences = (module, { id, modules, blocks }) => {
2469+
if (id !== chunkGraph.getModuleId(module)) return false;
24672470
if (modules !== undefined) {
24682471
for (const [module, id] of modules) {
24692472
if (chunkGraph.getModuleId(module) !== id) return false;
@@ -2489,7 +2492,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
24892492
};
24902493

24912494
for (const [module, memCache] of moduleMemCaches) {
2492-
/** @type {{ references: { modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
2495+
/** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
24932496
const cache = memCache.get(key);
24942497
if (cache === undefined) {
24952498
const memCache2 = new WeakTupleMap();

test/watchCases/cache/changing-module-id/0/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import value from "./module";
22
import value2 from "./unrelated";
33
import value3 from "./other-module";
44

5-
it("should work when modules change ids", () => {
5+
it("should work when modules change ids", async () => {
66
expect(value).toBe(42);
77
expect(value2).toBe(42);
88
expect(value3).toBe(42 + +WATCH_STEP);
9+
expect(import("./module?async")).resolves.toEqual(nsObj({ default: 42 }));
910
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default } from "./module";
2+
if (Math.random() < 0) import("./module?async");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default } from "./module";
2+
import "./module?async";

test/watchCases/cache/changing-module-id/webpack.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = {
55
type: "memory"
66
},
77
optimization: {
8-
sideEffects: false
8+
sideEffects: false,
9+
providedExports: false
910
},
1011
module: {
1112
rules: [
@@ -16,6 +17,7 @@ module.exports = {
1617
]
1718
},
1819
experiments: {
20+
cacheUnaffected: true,
1921
layers: true
2022
}
2123
};

0 commit comments

Comments
 (0)