fix: allow multiple runtime instances to receive HMR updates #10426
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
The current rspack runtime assigns a global HMR JSONP loader that replaces any existing loader with the same name. While usually a single instance of the same runtime is running on the same context, we found some cases in Module Federation where running the same remoteEntry more than once (and therefore the webpack runtime) in the same page allows to have coexisting instances of the same runtime. However, since the HMR JSONP loader is overwritten by the latest instance, only the latest instance gets the updates, causing errors in the earlier instances.
See the following scenario.
Before the fix:
2025-05-20.13-29-12.mp4
After the fix:
2025-05-20.13-27-38.mp4
The proposed fix consists of installing a JSONP loader that calls previous existing JSONP loaders in the scope. Since all instances trigger HMR updates sequentially, we also rely on
currentUpdate
to determine which instance needs the HMR update (if an old instance is waiting for the HMR update and the JSONP loader is executed before newer instances have requested the update, the newer instances might not even have setcurrentUpdate
up at that time)Our real use case is:
For completeness, here's the discussion I've had on webpack. Same changes have been proposed, since the runtime seems to be the same.
webpack/webpack#19543
Checklist