From c6923cc3de9ac7838c352d36dcea13756f1a4e9b Mon Sep 17 00:00:00 2001 From: pshu Date: Tue, 28 Oct 2025 15:19:16 +0800 Subject: [PATCH 1/3] fix: treat HMR's `warnUnexpectedRequire` as undefined module factory --- .../runtime_module/runtime/javascript_hot_module_replacement.js | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.js b/crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.js index c2e145f8fa61..374e41b5b672 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.js +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.js @@ -98,6 +98,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 8fbd0e791dc1f8253da41151483ddb55c7ec6302 Mon Sep 17 00:00:00 2001 From: pshu Date: Wed, 29 Oct 2025 18:52:00 +0800 Subject: [PATCH 2/3] test: update snapshots --- .../update-chunk-loading-runtime/__snapshots__/web/1.snap.txt | 3 ++- .../__snapshots__/web/1.snap.txt | 3 ++- .../runtime-independent-filename/__snapshots__/web/1.snap.txt | 3 ++- .../module/access-dropped-module/__snapshots__/web/1.snap.txt | 3 ++- .../hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt index 5d04419703a2..6ad3f9c734df 100644 --- a/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt @@ -11,7 +11,7 @@ - Bundle: vendors-node_modules_vendor_js.js - Manifest: runtime~main.LAST_HASH.hot-update.json, size: 76 - Update: main.LAST_HASH.hot-update.js, size: 714 -- Update: runtime~main.LAST_HASH.hot-update.js, size: 18966 +- Update: runtime~main.LAST_HASH.hot-update.js, size: 19038 - Update: vendors-node_modules_vendor_js.LAST_HASH.hot-update.js, size: 513 ## Manifest @@ -309,6 +309,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/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt index b0fe00a35440..acfd3dd6e971 100644 --- a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt @@ -8,7 +8,7 @@ - Bundle: chunk1_js.chunk.CURRENT_HASH.js - Manifest: [runtime of chunk2_js].LAST_HASH.hot-update.json, size: 60 - Manifest: main.LAST_HASH.hot-update.json, size: 41 -- Update: main.LAST_HASH.hot-update.js, size: 18468 +- Update: main.LAST_HASH.hot-update.js, size: 18540 ## Manifest @@ -267,6 +267,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/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt index ce348f80e785..50cbabe0abc2 100644 --- a/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Bundle: chunk1_js.chunk.CURRENT_HASH.js -- Update: main.LAST_HASH.hot-update.js, size: 18468 +- Update: main.LAST_HASH.hot-update.js, size: 18540 ## Manifest @@ -251,6 +251,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/module/access-dropped-module/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/module/access-dropped-module/__snapshots__/web/1.snap.txt index 408dea270321..fc1808de632d 100644 --- a/tests/rspack-test/hotCases/module/access-dropped-module/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/module/access-dropped-module/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 42 -- Update: main.LAST_HASH.hot-update.js, size: 15415 +- Update: main.LAST_HASH.hot-update.js, size: 15487 ## Manifest @@ -201,6 +201,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/sharing/share-plugin/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt index ed68b7d677d6..ccd28770d8da 100644 --- a/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ - Bundle: bundle.js - Bundle: common_js_2.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 42484 +- Update: main.LAST_HASH.hot-update.js, size: 42556 ## Manifest @@ -878,6 +878,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 a282fa9267f4d676712e9158156a525ef94a90e8 Mon Sep 17 00:00:00 2001 From: pshu Date: Thu, 30 Oct 2025 14:37:37 +0800 Subject: [PATCH 3/3] test: adjust test to catch disposed module error --- .../hotCases/runtime/require-disposed-module-warning/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/index.js b/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/index.js index 5f903f672a4f..1826a5b54faa 100644 --- a/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/index.js +++ b/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/index.js @@ -3,7 +3,7 @@ const getInner = require("./module"); it("should print correct warning messages when a disposed module is required", async () => { await NEXT_HMR(); - getInner(); + try { getInner(); } catch (e) { } expectWarning( /^\[HMR] unexpected require\(\.\/a.js\) from disposed module \.\/module\.js$/, /^\[HMR] unexpected require\(\.\/a.js\) to disposed module$/