diff --git a/lib/Compilation.js b/lib/Compilation.js index f13e2968610..efdeaa1b608 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -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, blocks?: (string | number)[] }} references + * @returns {{ id: string | number, modules?: Map, blocks?: (string | number)[] }} references */ const computeReferences = module => { + const id = chunkGraph.getModuleId(module); /** @type {Map} */ let modules = undefined; /** @type {(string | number)[] | undefined} */ @@ -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=} 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; @@ -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, blocks?: (string | number)[]}, memCache: WeakTupleMap }} */ + /** @type {{ references: { id: string | number, modules?: Map, blocks?: (string | number)[]}, memCache: WeakTupleMap }} */ const cache = memCache.get(key); if (cache === undefined) { const memCache2 = new WeakTupleMap(); diff --git a/test/watchCases/cache/changing-module-id/0/index.js b/test/watchCases/cache/changing-module-id/0/index.js index 65c14ab6919..b933cd1cd1d 100644 --- a/test/watchCases/cache/changing-module-id/0/index.js +++ b/test/watchCases/cache/changing-module-id/0/index.js @@ -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 })); }); diff --git a/test/watchCases/cache/changing-module-id/0/unrelated.js b/test/watchCases/cache/changing-module-id/0/unrelated.js index f79b64f9e4d..3b44be3ed19 100644 --- a/test/watchCases/cache/changing-module-id/0/unrelated.js +++ b/test/watchCases/cache/changing-module-id/0/unrelated.js @@ -1 +1,2 @@ export { default } from "./module"; +if (Math.random() < 0) import("./module?async"); diff --git a/test/watchCases/cache/changing-module-id/1/other-layer.js b/test/watchCases/cache/changing-module-id/1/other-layer.js index f79b64f9e4d..c29038c754b 100644 --- a/test/watchCases/cache/changing-module-id/1/other-layer.js +++ b/test/watchCases/cache/changing-module-id/1/other-layer.js @@ -1 +1,2 @@ export { default } from "./module"; +import "./module?async"; diff --git a/test/watchCases/cache/changing-module-id/webpack.config.js b/test/watchCases/cache/changing-module-id/webpack.config.js index a5df8d6947e..04720f340aa 100644 --- a/test/watchCases/cache/changing-module-id/webpack.config.js +++ b/test/watchCases/cache/changing-module-id/webpack.config.js @@ -5,7 +5,8 @@ module.exports = { type: "memory" }, optimization: { - sideEffects: false + sideEffects: false, + providedExports: false }, module: { rules: [ @@ -16,6 +17,7 @@ module.exports = { ] }, experiments: { + cacheUnaffected: true, layers: true } };