From ec9ae18ad7f9f1382604819f1e06d3707e979dc1 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 7 Nov 2025 15:19:57 +0800 Subject: [PATCH 1/4] fix: should not inject css prefetch/preload runtime when only prefetch javascript chunks --- crates/rspack_core/src/chunk.rs | 73 ++++++++++++++----- .../asset-modules/errored/test.filter.js | 2 +- .../configCases/css/import/index.js | 6 +- .../configCases/css/import/test.config.js | 5 +- .../configCases/css/import/test.filter.js | 2 +- .../css/prefetch-preload-module/index.mjs | 12 ++- .../prefetch-preload-module-only-js/index.mjs | 1 - .../test.filter.js | 1 - .../web/prefetch-preload-module/index.mjs | 15 ++-- .../css/stylesheet.css.js | 9 --- .../loader-import-module/css/test.filter.js | 2 +- .../runtime/root-error/test.filter.js | 2 +- .../worker/remove-add-worker/test.config.js | 8 ++ .../worker/remove-add-worker/test.filter.js | 4 - 14 files changed, 83 insertions(+), 59 deletions(-) delete mode 100644 tests/rspack-test/configCases/web/prefetch-preload-module-only-js/test.filter.js create mode 100644 tests/rspack-test/hotCases/worker/remove-add-worker/test.config.js delete mode 100644 tests/rspack-test/hotCases/worker/remove-add-worker/test.filter.js diff --git a/crates/rspack_core/src/chunk.rs b/crates/rspack_core/src/chunk.rs index 44688dd22de3..2bfca3cf99a0 100644 --- a/crates/rspack_core/src/chunk.rs +++ b/crates/rspack_core/src/chunk.rs @@ -809,30 +809,63 @@ impl Chunk { pub fn get_child_ids_by_order bool>( &self, - order: &ChunkGroupOrderKey, + order_key: &ChunkGroupOrderKey, compilation: &Compilation, filter_fn: &F, ) -> Option> { - self - .get_children_of_type_in_order(order, compilation, true) - .map(|order_children| { - order_children - .iter() - .flat_map(|(_, child_chunks)| { - child_chunks.iter().filter_map(|chunk_ukey| { - if filter_fn(chunk_ukey, compilation) { - compilation - .chunk_by_ukey - .expect_get(chunk_ukey) - .id(&compilation.chunk_ids_artifact) - .cloned() - } else { - None - } + let mut list = vec![]; + for group_ukey in self.get_sorted_groups_iter(&compilation.chunk_group_by_ukey) { + let group = compilation.chunk_group_by_ukey.expect_get(group_ukey); + if group + .chunks + .last() + .is_some_and(|chunk_ukey| chunk_ukey.eq(&self.ukey)) + { + for child_group_ukey in group.children_iterable() { + let child_group = compilation.chunk_group_by_ukey.expect_get(child_group_ukey); + if let Some(order) = child_group + .kind + .get_normal_options() + .and_then(|o| match order_key { + ChunkGroupOrderKey::Prefetch => o.prefetch_order, + ChunkGroupOrderKey::Preload => o.preload_order, }) - }) - .collect_vec() - }) + { + list.push((order, *child_group_ukey)); + } + } + } + } + + list.sort_by(|a, b| { + let order = b.0.cmp(&a.0); + match order { + Ordering::Equal => compare_chunk_group(&a.1, &b.1, compilation), + _ => order, + } + }); + + let mut chunk_ids = vec![]; + for (_, child_group_ukey) in list.iter() { + let child_group = compilation.chunk_group_by_ukey.expect_get(child_group_ukey); + for chunk_ukey in child_group.chunks.iter() { + if filter_fn(chunk_ukey, compilation) + && let Some(chunk_id) = compilation + .chunk_by_ukey + .expect_get(chunk_ukey) + .id(&compilation.chunk_ids_artifact) + .cloned() + { + chunk_ids.push(chunk_id); + } + } + } + + if chunk_ids.is_empty() { + return None; + } + + Some(chunk_ids) } pub fn get_child_ids_by_orders_map bool + Sync>( diff --git a/tests/rspack-test/configCases/asset-modules/errored/test.filter.js b/tests/rspack-test/configCases/asset-modules/errored/test.filter.js index a576333f8b3d..7289b6d7ffa8 100644 --- a/tests/rspack-test/configCases/asset-modules/errored/test.filter.js +++ b/tests/rspack-test/configCases/asset-modules/errored/test.filter.js @@ -1 +1 @@ -module.exports = () => "FIXME: can not find the css folder" \ No newline at end of file +module.exports = () => "TODO: generate empty css asset when loader throws error" \ No newline at end of file diff --git a/tests/rspack-test/configCases/css/import/index.js b/tests/rspack-test/configCases/css/import/index.js index 4c89e85386f6..4c90802bfa39 100644 --- a/tests/rspack-test/configCases/css/import/index.js +++ b/tests/rspack-test/configCases/css/import/index.js @@ -1,13 +1,13 @@ import "./style.css"; -import path from "path"; it("should compile", () => { - const links = document.getElementsByTagName("link"); + const links = Array.from(document.getElementsByTagName("link")); + const path = __non_webpack_require__("path"); const css = []; // Skip first because import it by default for (const link of links.slice(1)) { - css.push(link.sheet.css); + css.push(getLinkSheet(link)); } expect(css).toMatchFileSnapshot(path.join(__SNAPSHOT__, 'bundle0.css.txt')); diff --git a/tests/rspack-test/configCases/css/import/test.config.js b/tests/rspack-test/configCases/css/import/test.config.js index dbfd43168887..8947e29ab25f 100644 --- a/tests/rspack-test/configCases/css/import/test.config.js +++ b/tests/rspack-test/configCases/css/import/test.config.js @@ -1,10 +1,11 @@ "use strict"; module.exports = { - moduleScope(scope) { + moduleScope(scope, stats) { + const __STATS_I__ = stats().__index__; const link = scope.window.document.createElement("link"); link.rel = "stylesheet"; - link.href = `bundle${scope.__STATS_I__}.css`; + link.href = `bundle${__STATS_I__}.css`; scope.window.document.head.appendChild(link); } }; diff --git a/tests/rspack-test/configCases/css/import/test.filter.js b/tests/rspack-test/configCases/css/import/test.filter.js index 2836f118a4c3..9e75b1a2dbe4 100644 --- a/tests/rspack-test/configCases/css/import/test.filter.js +++ b/tests/rspack-test/configCases/css/import/test.filter.js @@ -1 +1 @@ -module.exports = () => "FIXME: can not resolve errors"; \ No newline at end of file +module.exports = () => "TODO: support css/global"; \ No newline at end of file diff --git a/tests/rspack-test/configCases/css/prefetch-preload-module/index.mjs b/tests/rspack-test/configCases/css/prefetch-preload-module/index.mjs index 33adf9673f0f..86b97ef2ea35 100644 --- a/tests/rspack-test/configCases/css/prefetch-preload-module/index.mjs +++ b/tests/rspack-test/configCases/css/prefetch-preload-module/index.mjs @@ -36,21 +36,19 @@ it("should prefetch and preload child chunks on chunk load", () => { // Test normal script loading link = document.head._children[3]; expect(link._type).toBe("link"); - expect(link.rel).toBe("modulepreload"); - expect(link.href).toBe("https://example.com/public/path/chunk1-b.mjs"); - - link = document.head._children[4]; - expect(link._type).toBe("link"); expect(link.rel).toBe("preload"); expect(link.as).toBe("style"); expect(link.href).toBe("https://example.com/public/path/chunk1-a-css.css"); - link = document.head._children[5]; + link = document.head._children[4]; expect(link._type).toBe("link"); expect(link.rel).toBe("modulepreload"); expect(link.href).toBe("https://example.com/public/path/chunk1-a-css.mjs"); - + link = document.head._children[5]; + expect(link._type).toBe("link"); + expect(link.rel).toBe("modulepreload"); + expect(link.href).toBe("https://example.com/public/path/chunk1-b.mjs"); return promise.then(() => { expect(document.head._children).toHaveLength(8); diff --git a/tests/rspack-test/configCases/web/prefetch-preload-module-only-js/index.mjs b/tests/rspack-test/configCases/web/prefetch-preload-module-only-js/index.mjs index a1c31cacb47e..651db7fddfa5 100644 --- a/tests/rspack-test/configCases/web/prefetch-preload-module-only-js/index.mjs +++ b/tests/rspack-test/configCases/web/prefetch-preload-module-only-js/index.mjs @@ -25,7 +25,6 @@ it("should prefetch and preload child chunks on chunk load", () => { expect(link._type).toBe("link"); expect(link.rel).toBe("modulepreload"); expect(link.href).toBe("https://example.com/public/path/chunk1-b.mjs"); - expect(link.charset).toBe("utf-8"); expect(link.getAttribute("nonce")).toBe("nonce"); expect(link.crossOrigin).toBe("anonymous"); diff --git a/tests/rspack-test/configCases/web/prefetch-preload-module-only-js/test.filter.js b/tests/rspack-test/configCases/web/prefetch-preload-module-only-js/test.filter.js deleted file mode 100644 index 09871c9caa2f..000000000000 --- a/tests/rspack-test/configCases/web/prefetch-preload-module-only-js/test.filter.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = () => "FIXME: unexpected css prefetch/preload runtime" diff --git a/tests/rspack-test/configCases/web/prefetch-preload-module/index.mjs b/tests/rspack-test/configCases/web/prefetch-preload-module/index.mjs index 42c1198a2a54..344f2904e1fe 100644 --- a/tests/rspack-test/configCases/web/prefetch-preload-module/index.mjs +++ b/tests/rspack-test/configCases/web/prefetch-preload-module/index.mjs @@ -33,30 +33,29 @@ it("should prefetch and preload child chunks on chunk load", () => { expect(document.head._children).toHaveLength(6); // Test normal script loading - // Test preload of chunk1-b link = document.head._children[3]; expect(link._type).toBe("link"); - expect(link.rel).toBe("modulepreload"); - expect(link.href).toBe("https://example.com/public/path/chunk1-b.mjs"); + expect(link.rel).toBe("preload"); + expect(link.as).toBe("style"); + expect(link.href).toBe("https://example.com/public/path/chunk1-a-css.css"); expect(link.getAttribute("nonce")).toBe("nonce"); expect(link.crossOrigin).toBe("anonymous"); link = document.head._children[4]; expect(link._type).toBe("link"); - expect(link.rel).toBe("preload"); - expect(link.as).toBe("style"); - expect(link.href).toBe("https://example.com/public/path/chunk1-a-css.css"); + expect(link.rel).toBe("modulepreload"); + expect(link.href).toBe("https://example.com/public/path/chunk1-a-css.mjs"); expect(link.getAttribute("nonce")).toBe("nonce"); expect(link.crossOrigin).toBe("anonymous"); + // Test preload of chunk1-b link = document.head._children[5]; expect(link._type).toBe("link"); expect(link.rel).toBe("modulepreload"); - expect(link.href).toBe("https://example.com/public/path/chunk1-a-css.mjs"); + expect(link.href).toBe("https://example.com/public/path/chunk1-b.mjs"); expect(link.getAttribute("nonce")).toBe("nonce"); expect(link.crossOrigin).toBe("anonymous"); - return promise.then(() => { expect(document.head._children).toHaveLength(8); diff --git a/tests/rspack-test/hotCases/loader-import-module/css/stylesheet.css.js b/tests/rspack-test/hotCases/loader-import-module/css/stylesheet.css.js index dec22b62b3cc..6e0bf75cf9f0 100644 --- a/tests/rspack-test/hotCases/loader-import-module/css/stylesheet.css.js +++ b/tests/rspack-test/hotCases/loader-import-module/css/stylesheet.css.js @@ -4,9 +4,6 @@ export default () => new URL("./file.png", import.meta.url).href }"); color: ${color}; }`; -if (import.meta.webpackHot) { - import.meta.webpackHot.accept("./colors.js"); -} --- import { color } from "./colors.js"; export default () => @@ -14,9 +11,6 @@ export default () => new URL("./file.png", import.meta.url).href }"); color: ${color}; }`; -if (import.meta.webpackHot) { - import.meta.webpackHot.accept("./colors.js"); -} --- import { color } from "./colors.js"; export default () => @@ -24,6 +18,3 @@ export default () => new URL("./file.jpg", import.meta.url).href }"); color: ${color}; }`; -if (import.meta.webpackHot) { - import.meta.webpackHot.accept("./colors.js"); -} diff --git a/tests/rspack-test/hotCases/loader-import-module/css/test.filter.js b/tests/rspack-test/hotCases/loader-import-module/css/test.filter.js index f427081e6f97..868b3d662338 100644 --- a/tests/rspack-test/hotCases/loader-import-module/css/test.filter.js +++ b/tests/rspack-test/hotCases/loader-import-module/css/test.filter.js @@ -1 +1 @@ -module.exports = () => "FIXME: timeout" +module.exports = () => true diff --git a/tests/rspack-test/hotCases/runtime/root-error/test.filter.js b/tests/rspack-test/hotCases/runtime/root-error/test.filter.js index 59287270b26f..371bcd0d38be 100644 --- a/tests/rspack-test/hotCases/runtime/root-error/test.filter.js +++ b/tests/rspack-test/hotCases/runtime/root-error/test.filter.js @@ -1,2 +1,2 @@ -module.exports = () => "FIXME: recovery failed" +module.exports = () => "TODO: support root error recovery" diff --git a/tests/rspack-test/hotCases/worker/remove-add-worker/test.config.js b/tests/rspack-test/hotCases/worker/remove-add-worker/test.config.js new file mode 100644 index 000000000000..020eeaa42c49 --- /dev/null +++ b/tests/rspack-test/hotCases/worker/remove-add-worker/test.config.js @@ -0,0 +1,8 @@ +module.exports = { + moduleScope(ms) { + ms._globalAssign = { + ...ms._globalAssign, + Worker: ms.Worker, + }; + } +}; \ No newline at end of file diff --git a/tests/rspack-test/hotCases/worker/remove-add-worker/test.filter.js b/tests/rspack-test/hotCases/worker/remove-add-worker/test.filter.js deleted file mode 100644 index 13e6c583edd2..000000000000 --- a/tests/rspack-test/hotCases/worker/remove-add-worker/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = function (config) { - // FIXME: not stable on CI - return false; -}; From e0f159c892258ee6cd921e3473beb02ed88fef7f Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 7 Nov 2025 16:28:21 +0800 Subject: [PATCH 2/4] fix: should not inject css prefetch/preload runtime when only prefetch javascript chunks --- .../css/__snapshots__/web/0.snap.txt | 12 +++ .../css/__snapshots__/web/1.snap.txt | 53 ++++++++++ .../css/__snapshots__/web/2.snap.txt | 98 +++++++++++++++++++ .../__snapshots__/web/1.snap.txt | 3 +- .../__snapshots__/web/2.snap.txt | 3 +- .../__snapshots__/web/3.snap.txt | 3 +- .../__snapshots__/web/5.snap.txt | 13 +-- 7 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/0.snap.txt create mode 100644 tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/1.snap.txt create mode 100644 tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/2.snap.txt diff --git a/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/0.snap.txt b/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/0.snap.txt new file mode 100644 index 000000000000..8a4dc1e3b67b --- /dev/null +++ b/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/0.snap.txt @@ -0,0 +1,12 @@ +# Case css: Step 0 + +## Changed Files + + +## Asset Files +- Bundle: bundle.js + +## Manifest + + +## Update \ No newline at end of file diff --git a/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/1.snap.txt new file mode 100644 index 000000000000..bb892c41764f --- /dev/null +++ b/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/1.snap.txt @@ -0,0 +1,53 @@ +# Case css: Step 1 + +## Changed Files +- colors.js +- stylesheet.css.js + +## Asset Files +- Bundle: bundle.js +- Manifest: main.LAST_HASH.hot-update.json, size: 28 +- Update: main.LAST_HASH.hot-update.js, size: 436 + +## Manifest + +### main.LAST_HASH.hot-update.json + +```json +{"c":["main"],"r":[],"m":[]} +``` + + +## Update + + +### main.LAST_HASH.hot-update.js + +#### Changed Modules +- ./stylesheet.css.js + +#### Changed Runtime Modules +- webpack/runtime/get_full_hash + +#### Changed Content +```js +"use strict"; +self["webpackHotUpdate"]("main", { +"./stylesheet.css.js": +/*!***************************!*\ + !*** ./stylesheet.css.js ***! + \***************************/ +(function (module) { +module.exports = "body { background: url(\"https://test.cases/path/assets/file.png\"); color: #0f0; }"; + +}), + +},function(__webpack_require__) { +// webpack/runtime/get_full_hash +(() => { +__webpack_require__.h = () => ("CURRENT_HASH") +})(); + +} +); +``` \ No newline at end of file diff --git a/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/2.snap.txt new file mode 100644 index 000000000000..1c38c8975472 --- /dev/null +++ b/tests/rspack-test/hotCases/loader-import-module/css/__snapshots__/web/2.snap.txt @@ -0,0 +1,98 @@ +# Case css: Step 2 + +## Changed Files +- colors.js +- stylesheet.css.js + +## Asset Files +- Bundle: bundle.js +- Manifest: main.LAST_HASH.hot-update.json, size: 28 +- Update: main.LAST_HASH.hot-update.js, size: 436 + +## Manifest + +### main.LAST_HASH.hot-update.json + +```json +{"c":["main"],"r":[],"m":[]} +``` + + +## Update + + +### main.LAST_HASH.hot-update.js + +#### Changed Modules +- ./stylesheet.css.js + +#### Changed Runtime Modules +- webpack/runtime/get_full_hash + +#### Changed Content +```js +"use strict"; +self["webpackHotUpdate"]("main", { +"./stylesheet.css.js": +/*!***************************!*\ + !*** ./stylesheet.css.js ***! + \***************************/ +(function (module) { +module.exports = "body { background: url(\"https://test.cases/path/assets/file.jpg\"); color: #00f; }"; + +}), + +},function(__webpack_require__) { +// webpack/runtime/get_full_hash +(() => { +__webpack_require__.h = () => ("CURRENT_HASH") +})(); + +} +); +``` + + + + +## Runtime +### Status + +```txt +check => prepare => dispose => apply => idle +``` + + + +### JavaScript + +#### Outdated + +Outdated Modules: +- ./stylesheet.css.js + + +Outdated Dependencies: +```json +{ + "./index.js": [ + "./stylesheet.css.js" + ] +} +``` + +#### Updated + +Updated Modules: +- ./stylesheet.css.js + +Updated Runtime: +- `__webpack_require__.h` + + +#### Callback + +Accepted Callback: +- ./stylesheet.css.js + +Disposed Callback: \ No newline at end of file diff --git a/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/1.snap.txt index 1a4b11cc2ef9..40d8924a126d 100644 --- a/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ - Bundle: bundle.js - Bundle: worker_js.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 16521 +- Update: main.LAST_HASH.hot-update.js, size: 16593 ## Manifest @@ -232,6 +232,7 @@ function applyHandler(options) { console.warn( "[HMR] unexpected require(" + module.id + ") to disposed module" ); + throw Error("RuntimeError: factory is undefined(" + module.id + ")"); }; for (var moduleId in currentUpdate) { diff --git a/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/2.snap.txt index 3c647b829d53..4135b5b92efa 100644 --- a/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/2.snap.txt @@ -7,7 +7,7 @@ - Bundle: bundle.js - Manifest: [runtime of worker_js].LAST_HASH.hot-update.json, size: 46 - Manifest: main.LAST_HASH.hot-update.json, size: 41 -- Update: main.LAST_HASH.hot-update.js, size: 15730 +- Update: main.LAST_HASH.hot-update.js, size: 15802 ## Manifest @@ -215,6 +215,7 @@ function applyHandler(options) { console.warn( "[HMR] unexpected require(" + module.id + ") to disposed module" ); + throw Error("RuntimeError: factory is undefined(" + module.id + ")"); }; for (var moduleId in currentUpdate) { diff --git a/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/3.snap.txt index 133613227d0e..a89d0e6ebc24 100644 --- a/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/3.snap.txt @@ -7,7 +7,7 @@ - Bundle: bundle.js - Bundle: worker_js.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 16521 +- Update: main.LAST_HASH.hot-update.js, size: 16593 ## Manifest @@ -232,6 +232,7 @@ function applyHandler(options) { console.warn( "[HMR] unexpected require(" + module.id + ") to disposed module" ); + throw Error("RuntimeError: factory is undefined(" + module.id + ")"); }; for (var moduleId in currentUpdate) { diff --git a/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/5.snap.txt b/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/5.snap.txt index e209527b66ca..4a7afbaddd95 100644 --- a/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/5.snap.txt +++ b/tests/rspack-test/hotCases/worker/remove-add-worker/__snapshots__/web/5.snap.txt @@ -6,26 +6,26 @@ ## Asset Files - Bundle: bundle.js - Bundle: worker_js.chunk.CURRENT_HASH.js +- Manifest: 82972a065b3b6dad.LAST_HASH.hot-update.json, size: 62 - Manifest: [runtime of worker_js_1].LAST_HASH.hot-update.json, size: 61 -- Manifest: d034dd2aafd4d854.LAST_HASH.hot-update.json, size: 62 - Manifest: main.LAST_HASH.hot-update.json, size: 43 - Update: main.LAST_HASH.hot-update.js, size: 1002 -- Update: worker_js.LAST_HASH.hot-update.js, size: 14367 +- Update: worker_js.LAST_HASH.hot-update.js, size: 14439 ## Manifest -### [runtime of worker_js_1].LAST_HASH.hot-update.json +### 82972a065b3b6dad.LAST_HASH.hot-update.json ```json -{"c":["worker_js"],"r":["worker_js_1"],"m":["./worker.js?1"]} +{"c":[],"r":["worker_js"],"m":["./worker.js","./worker.js?1"]} ``` -### d034dd2aafd4d854.LAST_HASH.hot-update.json +### [runtime of worker_js_1].LAST_HASH.hot-update.json ```json -{"c":[],"r":["worker_js"],"m":["./worker.js","./worker.js?1"]} +{"c":["worker_js"],"r":["worker_js_1"],"m":["./worker.js?1"]} ``` @@ -227,6 +227,7 @@ function applyHandler(options) { console.warn( "[HMR] unexpected require(" + module.id + ") to disposed module" ); + throw Error("RuntimeError: factory is undefined(" + module.id + ")"); }; for (var moduleId in currentUpdate) { From f07209c3a22b8e43cad2f2970b8c803acd7ab71d Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 7 Nov 2025 17:25:13 +0800 Subject: [PATCH 3/4] fix: should not inject css prefetch/preload runtime when only prefetch javascript chunks --- packages/rspack-test-tools/src/case/hot-step.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/rspack-test-tools/src/case/hot-step.ts b/packages/rspack-test-tools/src/case/hot-step.ts index fb39b9a90a80..e4e042d8fd63 100644 --- a/packages/rspack-test-tools/src/case/hot-step.ts +++ b/packages/rspack-test-tools/src/case/hot-step.ts @@ -150,8 +150,9 @@ function createHotStepProcessor( }, str); }; - const fileList = stats - .assets!.map(i => { + const assets = stats.assets!.sort((a, b) => a.name.localeCompare(b.name)); + const fileList = assets + .map(i => { const fileName = i.name; const renderName = replaceFileName(fileName); const content = replaceContent( From 01284420d3c7d31c80a566f0c17603af971da0e7 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 7 Nov 2025 17:50:45 +0800 Subject: [PATCH 4/4] fix: should not inject css prefetch/preload runtime when only prefetch javascript chunks --- tests/rspack-test/HotSnapshot.hottest.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/rspack-test/HotSnapshot.hottest.js b/tests/rspack-test/HotSnapshot.hottest.js index ac6ddfc0e41e..cf2086aa829e 100644 --- a/tests/rspack-test/HotSnapshot.hottest.js +++ b/tests/rspack-test/HotSnapshot.hottest.js @@ -6,5 +6,6 @@ describeByWalk(__filename, (name, src, dist) => { createHotStepCase(name, src, dist, path.join(tempDir, name), "web"); }, { source: path.resolve(__dirname, "./hotCases"), - dist: path.resolve(__dirname, `./js/hot-snapshot`) + dist: path.resolve(__dirname, `./js/hot-snapshot`), + exclude: [/remove-add-worker/] });