Skip to content

Conversation

@stormslowly
Copy link
Contributor

@stormslowly stormslowly commented Oct 28, 2025

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 undefined to trigger rspack-contrib/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

  • Tests updated (or not required).
  • Documentation updated (or not required).

@netlify
Copy link

netlify bot commented Oct 28, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit a282fa9
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/690307e056fdeb0008b14399

@github-actions github-actions bot added release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack. labels Oct 28, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2025

📦 Binary Size-limit

Comparing a282fa9 to refactor: EsmLibraryPlugin should hold itself lock of data (#12035) by Fy

🙈 Size remains the same at 47.81MB

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 28, 2025

CodSpeed Performance Report

Merging #12016 will not alter performance

Comparing fix/hmr_chunk_apply_race_condition (a282fa9) with main (fe6d1dc)

Summary

✅ 17 untouched

@stormslowly stormslowly marked this pull request as ready for review October 31, 2025 04:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 warnUnexpectedRequire function 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RuntimeError: factory is undefined during HMR of lazy-loaded React component with a specific dependency.

2 participants