From 9bce51f651aad297ef9eb6df832bfdaf1de05d84 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期三, 22 四月 2026 14:27:54 +0800
Subject: [PATCH] 青岛推送

---
 node_modules/webpack/lib/HotModuleReplacementPlugin.js |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/node_modules/webpack/lib/HotModuleReplacementPlugin.js b/node_modules/webpack/lib/HotModuleReplacementPlugin.js
index 0eafc40..2f92bfc 100644
--- a/node_modules/webpack/lib/HotModuleReplacementPlugin.js
+++ b/node_modules/webpack/lib/HotModuleReplacementPlugin.js
@@ -19,6 +19,7 @@
 const NormalModule = require("./NormalModule");
 const RuntimeGlobals = require("./RuntimeGlobals");
 const WebpackError = require("./WebpackError");
+const { chunkHasCss } = require("./css/CssModulesPlugin");
 const ConstDependency = require("./dependencies/ConstDependency");
 const ImportMetaHotAcceptDependency = require("./dependencies/ImportMetaHotAcceptDependency");
 const ImportMetaHotDeclineDependency = require("./dependencies/ImportMetaHotDeclineDependency");
@@ -62,6 +63,7 @@
 /** @typedef {string[]} Requests */
 
 /**
+ * Defines the hmr javascript parser hooks type used by this module.
  * @typedef {object} HMRJavascriptParserHooks
  * @property {SyncBailHook<[Expression | SpreadElement, Requests], void>} hotAcceptCallback
  * @property {SyncBailHook<[CallExpression, Requests], void>} hotAcceptWithoutCallback
@@ -74,7 +76,10 @@
 /** @typedef {Record<ChunkId, string>} ChunkRuntime */
 /** @typedef {Record<ChunkId, ModuleId[]>} ChunkModuleIds */
 
-/** @typedef {{ updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }} HotUpdateMainContentByRuntimeItem */
+/** @typedef {Set<ChunkId>} ChunkIds */
+/** @typedef {Set<Module>} ModuleSet */
+
+/** @typedef {{ updatedChunkIds: ChunkIds, removedChunkIds: ChunkIds, removedModules: ModuleSet, filename: string, assetInfo: AssetInfo }} HotUpdateMainContentByRuntimeItem */
 /** @typedef {Map<string, HotUpdateMainContentByRuntimeItem>} HotUpdateMainContentByRuntime */
 
 /** @type {WeakMap<JavascriptParser, HMRJavascriptParserHooks>} */
@@ -84,6 +89,7 @@
 
 class HotModuleReplacementPlugin {
 	/**
+	 * Returns the attached hooks.
 	 * @param {JavascriptParser} parser the parser
 	 * @returns {HMRJavascriptParserHooks} the attached hooks
 	 */
@@ -105,7 +111,7 @@
 	}
 
 	/**
-	 * Apply the plugin
+	 * Applies the plugin by registering its hooks on the compiler.
 	 * @param {Compiler} compiler the compiler instance
 	 * @returns {void}
 	 */
@@ -117,6 +123,7 @@
 		const runtimeRequirements = [RuntimeGlobals.module];
 
 		/**
+		 * Creates an accept handler.
 		 * @param {JavascriptParser} parser the parser
 		 * @param {typeof ModuleHotAcceptDependency} ParamDependency dependency
 		 * @returns {(expr: CallExpression) => boolean | undefined} callback
@@ -183,6 +190,7 @@
 		};
 
 		/**
+		 * Creates a decline handler.
 		 * @param {JavascriptParser} parser the parser
 		 * @param {typeof ModuleHotDeclineDependency} ParamDependency dependency
 		 * @returns {(expr: CallExpression) => boolean | undefined} callback
@@ -224,6 +232,7 @@
 		};
 
 		/**
+		 * Creates a hmr expression handler.
 		 * @param {JavascriptParser} parser the parser
 		 * @returns {(expr: Expression) => boolean | undefined} callback
 		 */
@@ -242,6 +251,7 @@
 		};
 
 		/**
+		 * Processes the provided parser.
 		 * @param {JavascriptParser} parser the parser
 		 * @returns {void}
 		 */
@@ -277,6 +287,7 @@
 		};
 
 		/**
+		 * Apply import meta hot.
 		 * @param {JavascriptParser} parser the parser
 		 * @returns {void}
 		 */
@@ -398,6 +409,7 @@
 					const records = /** @type {Records} */ (compilation.records);
 					for (const chunk of compilation.chunks) {
 						/**
+						 * Returns module hash.
 						 * @param {Module} module module
 						 * @returns {string} module hash
 						 */
@@ -516,6 +528,7 @@
 
 						/** @type {HotUpdateMainContentByRuntime} */
 						const hotUpdateMainContentByRuntime = new Map();
+						/** @type {RuntimeSpec} */
 						let allOldRuntime;
 						const chunkRuntime =
 							/** @type {ChunkRuntime} */
@@ -536,8 +549,11 @@
 							hotUpdateMainContentByRuntime.set(
 								/** @type {string} */ (runtime),
 								{
+									/** @type {ChunkIds} */
 									updatedChunkIds: new Set(),
+									/** @type {ChunkIds} */
 									removedChunkIds: new Set(),
+									/** @type {ModuleSet} */
 									removedModules: new Set(),
 									filename,
 									assetInfo
@@ -579,11 +595,17 @@
 
 							/** @type {ChunkId | null} */
 							let chunkId;
+							/** @type {undefined | Module[]} */
 							let newModules;
+							/** @type {undefined | RuntimeModule[]} */
 							let newRuntimeModules;
+							/** @type {undefined | RuntimeModule[]} */
 							let newFullHashModules;
+							/** @type {undefined | RuntimeModule[]} */
 							let newDependentHashModules;
+							/** @type {RuntimeSpec} */
 							let newRuntime;
+							/** @type {RuntimeSpec} */
 							let removedFromRuntime;
 							const currentChunk = find(
 								compilation.chunks,
@@ -774,6 +796,7 @@
 							}
 						}
 						const completelyRemovedModulesArray = [...completelyRemovedModules];
+						/** @type {Map<string, Omit<HotUpdateMainContentByRuntimeItem, "filename">>} */
 						const hotUpdateMainContentByFilename = new Map();
 						for (const {
 							removedChunkIds,
@@ -817,6 +840,7 @@
 							filename,
 							{ removedChunkIds, removedModules, updatedChunkIds, assetInfo }
 						] of hotUpdateMainContentByFilename) {
+							/** @type {{ c: ChunkId[], r: ChunkId[], m: ModuleId[], css?: { r: ChunkId[] } }} */
 							const hotUpdateMainJson = {
 								c: [...updatedChunkIds],
 								r: [...removedChunkIds],
@@ -833,6 +857,26 @@
 											]
 							};
 
+							// Build CSS removed chunks list (chunks in updatedChunkIds that no longer have CSS)
+							/** @type {ChunkId[]} */
+							const cssRemovedChunkIds = [];
+							if (compilation.options.experiments.css) {
+								for (const chunkId of updatedChunkIds) {
+									for (const /** @type {Chunk} */ chunk of compilation.chunks) {
+										if (chunk.id === chunkId) {
+											if (!chunkHasCss(chunk, chunkGraph)) {
+												cssRemovedChunkIds.push(chunkId);
+											}
+											break;
+										}
+									}
+								}
+							}
+
+							if (cssRemovedChunkIds.length > 0) {
+								hotUpdateMainJson.css = { r: cssRemovedChunkIds };
+							}
+
 							const source = new RawSource(
 								(filename.endsWith(".json") ? "" : "export default ") +
 									JSON.stringify(hotUpdateMainJson)

--
Gitblit v1.9.3