fix: treat HMR's warnUnexpectedRequire as undefined module factory#12016
Merged
stormslowly merged 5 commits intomainfrom Nov 4, 2025
Merged
fix: treat HMR's warnUnexpectedRequire as undefined module factory#12016stormslowly merged 5 commits intomainfrom
warnUnexpectedRequire as undefined module factory#12016stormslowly merged 5 commits intomainfrom
Conversation
✅ Deploy Preview for rspack canceled.
|
Contributor
📦 Binary Size-limit
🙈 Size remains the same at 47.81MB |
CodSpeed Performance ReportMerging #12016 will not alter performanceComparing Summary
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds error throwing behavior to the Hot Module Replacement (HMR) runtime when a disposed module is required. Previously, the system only warned about accessing disposed modules; now it throws an error after the warning to prevent continued execution with undefined module factories.
Key changes:
- Modified the
warnUnexpectedRequirefunction to throw an error after logging the warning - Updated test expectations to handle the newly thrown error
- Updated snapshot tests to reflect increased bundle sizes due to the added error handling code
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.js |
Added throw Error() statement to warnUnexpectedRequire function to prevent execution with undefined factory |
tests/rspack-test/hotCases/runtime/require-disposed-module-warning/index.js |
Wrapped getInner() call in try-catch to handle the newly thrown error |
tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt |
Updated snapshot to reflect increased bundle size and added error throwing code |
tests/rspack-test/hotCases/module/access-dropped-module/__snapshots__/web/1.snap.txt |
Updated snapshot to reflect increased bundle size and added error throwing code |
tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt |
Updated snapshot to reflect increased bundle size and added error throwing code |
tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt |
Updated snapshot to reflect increased bundle size and added error throwing code |
tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt |
Updated snapshot to reflect increased bundle size and added error throwing code |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.js
Show resolved
Hide resolved
tests/rspack-test/hotCases/runtime/require-disposed-module-warning/index.js
Show resolved
Hide resolved
LingyuCoder
approved these changes
Nov 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
close #11922
This case is similar to #11324 (comment).
A small difference is that the missing module's factory is replaced with an HMR runtime warning function. So when the required module is not ready yet, users have to reload to recover from this error.
As a workaround, we throw the specified error
RuntimeError: factory is undefinedto trigger rstackjs/rspack-plugin-react-refresh#50 to do a browser reload.By the way, we are planning a new HMR runtime to ensure a hot updated module's dependence chunks are loaded before it's required.
Related links
Checklist