fix: sort css by sourceorder, esm import comes first#12778
Conversation
Ensure dependencies with None source_order are placed after Some, preserving their relative order.
✅ Deploy Preview for rspack canceled.
|
a70197d to
a9e7615
Compare
There was a problem hiding this comment.
Pull request overview
This PR aims to fix CSS source order issues when mixing ESM import statements with CommonJS require() calls. The change modifies the dependency sorting logic in the chunk graph builder to ensure proper ordering of CSS modules regardless of how they're imported.
Changes:
- Modified dependency sorting in
code_splitter.rsto sort by whethersource_order()exists - Added test case verifying CSS cascade order with mixed ESM/CJS imports
- Added CSS files for the test case
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs |
Modified dependency sorting to use tuple key (is_none, source_order) instead of just source_order |
tests/rspack-test/configCases/css/mixed-import-require/index.js |
Test file importing CSS via ESM and CJS, expecting red color to win in CSS cascade |
tests/rspack-test/configCases/css/mixed-import-require/style1.css |
CSS file setting body color to red, imported via ESM |
tests/rspack-test/configCases/css/mixed-import-require/style2.css |
CSS file setting body color to blue, imported via CJS |
tests/rspack-test/configCases/css/mixed-import-require/rspack.config.js |
Test configuration enabling CSS experiments |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 2.63KB from 47.99MB to 48.00MB (⬆️0.01%) |
a9e7615 to
36e1f02
Compare
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
* fix(core): correct dependency sorting by source_order Ensure dependencies with None source_order are placed after Some, preserving their relative order. * test: add test case for css source order with mixed import and require
* fix(core): correct dependency sorting by source_order Ensure dependencies with None source_order are placed after Some, preserving their relative order. * test: add test case for css source order with mixed import and require
Summary
close #12765
buildChunkGraph will set preOrderIndex for each module. Each module is sorted by importer dependency's source_order. ESMImportSpecifierDependency's source_order returns Some while CommonjsRequireDependency returns None.
Sort ESM dependencies' order and make sure ESM dependencies always comes before CJS dependencies
Related links
Checklist