mirror of https://github.com/webpack/webpack.git
				
				
				
			fix a bug with experiments.cacheUnaffected
that causes missing invalidation for modules when only the module id has changed
This commit is contained in:
		
							parent
							
								
									86e3eb289f
								
							
						
					
					
						commit
						393fb6e22c
					
				| 
						 | 
					@ -2424,9 +2424,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
 | 
				
			||||||
		let statNew = 0;
 | 
							let statNew = 0;
 | 
				
			||||||
		/**
 | 
							/**
 | 
				
			||||||
		 * @param {Module} module module
 | 
							 * @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 computeReferences = module => {
 | 
				
			||||||
 | 
								const id = chunkGraph.getModuleId(module);
 | 
				
			||||||
			/** @type {Map<Module, string | number | undefined>} */
 | 
								/** @type {Map<Module, string | number | undefined>} */
 | 
				
			||||||
			let modules = undefined;
 | 
								let modules = undefined;
 | 
				
			||||||
			/** @type {(string | number)[] | 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);
 | 
										queue.push.apply(queue, block.blocks);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			return { modules, blocks };
 | 
								return { id, modules, blocks };
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
		/**
 | 
							/**
 | 
				
			||||||
		 * @param {Module} module module
 | 
							 * @param {Module} module module
 | 
				
			||||||
		 * @param {Object} references references
 | 
							 * @param {Object} references references
 | 
				
			||||||
 | 
							 * @param {string | number} references.id id
 | 
				
			||||||
		 * @param {Map<Module, string | number>=} references.modules modules
 | 
							 * @param {Map<Module, string | number>=} references.modules modules
 | 
				
			||||||
		 * @param {(string | number)[]=} references.blocks blocks
 | 
							 * @param {(string | number)[]=} references.blocks blocks
 | 
				
			||||||
		 * @returns {boolean} ok?
 | 
							 * @returns {boolean} ok?
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		const compareReferences = (module, { modules, blocks }) => {
 | 
							const compareReferences = (module, { id, modules, blocks }) => {
 | 
				
			||||||
 | 
								if (id !== chunkGraph.getModuleId(module)) return false;
 | 
				
			||||||
			if (modules !== undefined) {
 | 
								if (modules !== undefined) {
 | 
				
			||||||
				for (const [module, id] of modules) {
 | 
									for (const [module, id] of modules) {
 | 
				
			||||||
					if (chunkGraph.getModuleId(module) !== id) return false;
 | 
										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) {
 | 
							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);
 | 
								const cache = memCache.get(key);
 | 
				
			||||||
			if (cache === undefined) {
 | 
								if (cache === undefined) {
 | 
				
			||||||
				const memCache2 = new WeakTupleMap();
 | 
									const memCache2 = new WeakTupleMap();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,8 +2,9 @@ import value from "./module";
 | 
				
			||||||
import value2 from "./unrelated";
 | 
					import value2 from "./unrelated";
 | 
				
			||||||
import value3 from "./other-module";
 | 
					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(value).toBe(42);
 | 
				
			||||||
	expect(value2).toBe(42);
 | 
						expect(value2).toBe(42);
 | 
				
			||||||
	expect(value3).toBe(42 + +WATCH_STEP);
 | 
						expect(value3).toBe(42 + +WATCH_STEP);
 | 
				
			||||||
 | 
						expect(import("./module?async")).resolves.toEqual(nsObj({ default: 42 }));
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1 +1,2 @@
 | 
				
			||||||
export { default } from "./module";
 | 
					export { default } from "./module";
 | 
				
			||||||
 | 
					if (Math.random() < 0) import("./module?async");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1 +1,2 @@
 | 
				
			||||||
export { default } from "./module";
 | 
					export { default } from "./module";
 | 
				
			||||||
 | 
					import "./module?async";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,8 @@ module.exports = {
 | 
				
			||||||
		type: "memory"
 | 
							type: "memory"
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	optimization: {
 | 
						optimization: {
 | 
				
			||||||
		sideEffects: false
 | 
							sideEffects: false,
 | 
				
			||||||
 | 
							providedExports: false
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	module: {
 | 
						module: {
 | 
				
			||||||
		rules: [
 | 
							rules: [
 | 
				
			||||||
| 
						 | 
					@ -16,6 +17,7 @@ module.exports = {
 | 
				
			||||||
		]
 | 
							]
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	experiments: {
 | 
						experiments: {
 | 
				
			||||||
 | 
							cacheUnaffected: true,
 | 
				
			||||||
		layers: true
 | 
							layers: true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue