fix: optimize CSS runtime requirements logic#12529
Conversation
- Refactor runtime requirements check to be more granular - Only add CSS loading runtime module when HAS_CSS_MODULES is required - Only add PUBLIC_PATH and GET_CHUNK_CSS_FILENAME when needed - Fix test cases to match expected behavior
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes the CSS runtime requirements logic to reduce unnecessary runtime modules in the bundle. Previously, the CSS plugin would unconditionally add runtime requirements and modules even when they weren't needed.
Key changes:
- Refactored runtime requirements check to be more granular and conditional
- Only add CSS loading runtime module when
HAS_CSS_MODULESis required - Only add
PUBLIC_PATH,GET_CHUNK_CSS_FILENAME, andHAS_OWN_PROPERTYwhen specifically needed byENSURE_CHUNK_HANDLERSorHMR_DOWNLOAD_UPDATE_HANDLERS
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs | Refactored runtime requirements logic to conditionally add runtime modules and requirements based on specific feature usage |
| tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js | Updated test expectations to remove unnecessary runtime modules from source map |
| tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js | Updated module count expectation from 8 to 4, reflecting the reduction in unnecessary runtime modules |
| tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js | Added CSS import to test case to ensure CSS loading runtime requirements are properly triggered for HMR testing |
| tests/rspack-test/statsOutputCases/*/stats.txt | Updated snapshot files to reflect reduced runtime module counts (typically reduced by 1-2 modules) |
| tests/rspack-test/builtinCases/plugin-html/variant/output.snap.txt | Updated integrity hash due to changed runtime.js content after optimization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 1 project with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 ui-componentsPath:
📦 Download Diff Report: ui-components Bundle Diff Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
🙈 Size remains the same at 47.87MB |
CodSpeed Performance ReportMerging #12529 will not alter performanceComparing Summary
Footnotes
|
Summary
This PR optimizes the CSS runtime requirements logic to be more granular and only add runtime modules when they are actually needed. Previously, the CSS plugin would add runtime requirements and modules even when they weren't required, leading to unnecessary runtime code in the bundle.
The main changes include:
Checklist