Skip to content

Commit

Permalink
Merge pull request #14684 from webpack/bugfix/cache-unaffected-module-id
Browse files Browse the repository at this point in the history
fix a bug with experiments.cacheUnaffected
  • Loading branch information
sokra committed Nov 9, 2021
2 parents 86e3eb2 + 393fb6e commit 14582fc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
11 changes: 7 additions & 4 deletions lib/Compilation.js
Expand Up @@ -2424,9 +2424,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
let statNew = 0;
/**
* @param {Module} module module
* @returns {{ modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
* @returns {{ id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
*/
const computeReferences = module => {
const id = chunkGraph.getModuleId(module);
/** @type {Map<Module, string | number | undefined>} */
let modules = undefined;
/** @type {(string | number)[] | undefined} */
Expand Down Expand Up @@ -2454,16 +2455,18 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
queue.push.apply(queue, block.blocks);
}
}
return { modules, blocks };
return { id, modules, blocks };
};
/**
* @param {Module} module module
* @param {Object} references references
* @param {string | number} references.id id
* @param {Map<Module, string | number>=} references.modules modules
* @param {(string | number)[]=} references.blocks blocks
* @returns {boolean} ok?
*/
const compareReferences = (module, { modules, blocks }) => {
const compareReferences = (module, { id, modules, blocks }) => {
if (id !== chunkGraph.getModuleId(module)) return false;
if (modules !== undefined) {
for (const [module, id] of modules) {
if (chunkGraph.getModuleId(module) !== id) return false;
Expand All @@ -2489,7 +2492,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
};

for (const [module, memCache] of moduleMemCaches) {
/** @type {{ references: { modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
/** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
const cache = memCache.get(key);
if (cache === undefined) {
const memCache2 = new WeakTupleMap();
Expand Down
3 changes: 2 additions & 1 deletion test/watchCases/cache/changing-module-id/0/index.js
Expand Up @@ -2,8 +2,9 @@ import value from "./module";
import value2 from "./unrelated";
import value3 from "./other-module";

it("should work when modules change ids", () => {
it("should work when modules change ids", async () => {
expect(value).toBe(42);
expect(value2).toBe(42);
expect(value3).toBe(42 + +WATCH_STEP);
expect(import("./module?async")).resolves.toEqual(nsObj({ default: 42 }));
});
1 change: 1 addition & 0 deletions test/watchCases/cache/changing-module-id/0/unrelated.js
@@ -1 +1,2 @@
export { default } from "./module";
if (Math.random() < 0) import("./module?async");
1 change: 1 addition & 0 deletions test/watchCases/cache/changing-module-id/1/other-layer.js
@@ -1 +1,2 @@
export { default } from "./module";
import "./module?async";
4 changes: 3 additions & 1 deletion test/watchCases/cache/changing-module-id/webpack.config.js
Expand Up @@ -5,7 +5,8 @@ module.exports = {
type: "memory"
},
optimization: {
sideEffects: false
sideEffects: false,
providedExports: false
},
module: {
rules: [
Expand All @@ -16,6 +17,7 @@ module.exports = {
]
},
experiments: {
cacheUnaffected: true,
layers: true
}
};

0 comments on commit 14582fc

Please sign in to comment.