fix: should not panic if ref-cjs is removed#12147
Merged
Conversation
✅ Deploy Preview for rspack canceled.
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a panic that occurs when ref-cjs modules are optimized away during tree-shaking. The fix ensures that the code checks whether a connection is active before attempting to access the module identifier, preventing crashes when modules have been removed through optimization.
- Added check to skip modules that aren't in any chunks during preserve_modules processing
- Updated dependency handling to use connections and verify they're active before accessing module identifiers
- Added test case for tree-shaking side-effect-free modules
Reviewed Changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_plugin_esm_library/src/link.rs | Added checks for inactive connections and modules not in chunks to prevent panics when accessing optimized-away modules |
| tests/rspack-test/esmOutputCases/basic/tree-shaking/index.js | Test file importing a side-effect-free module to validate tree-shaking behavior |
| tests/rspack-test/esmOutputCases/basic/tree-shaking/node_modules/side-effect-free/package.json | Package configuration marking module as side-effect-free |
| tests/rspack-test/esmOutputCases/basic/tree-shaking/node_modules/side-effect-free/index.js | Empty module file for tree-shaking test |
| tests/rspack-test/esmOutputCases/basic/tree-shaking/snapshots/esm.snap.txt | Expected output snapshot showing tree-shaken result |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📦 Binary Size-limit
❌ Size increased by 384bytes from 48.09MB to 48.09MB (⬆️0.00%) |
CodSpeed Performance ReportMerging #12147 will not alter performanceComparing Summary
|
Timeless0911
approved these changes
Nov 11, 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
If ref cjs is optimized, should not get its chunk directly as it does not exist in any chunks
Related links
Checklist