Skip to content

Comments

fix: sort css by sourceorder, esm import comes first#12778

Merged
JSerFeng merged 2 commits intomainfrom
vk/3359-css-sourceorder
Jan 19, 2026
Merged

fix: sort css by sourceorder, esm import comes first#12778
JSerFeng merged 2 commits intomainfrom
vk/3359-css-sourceorder

Conversation

@JSerFeng
Copy link
Contributor

@JSerFeng JSerFeng commented Jan 19, 2026

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

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

Ensure dependencies with None source_order are placed after Some, preserving their relative order.
Copilot AI review requested due to automatic review settings January 19, 2026 06:14
@netlify
Copy link

netlify bot commented Jan 19, 2026

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 36e1f02
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/696dd078e0916c00087fb964

@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 Jan 19, 2026
@JSerFeng JSerFeng force-pushed the vk/3359-css-sourceorder branch from a70197d to a9e7615 Compare January 19, 2026 06:19
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 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.rs to sort by whether source_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.

@JSerFeng JSerFeng changed the title fix: css sourceorder fix: sort css by sourceorder, esm import comes first Jan 19, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 19, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 825.4 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.1 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Jan 19, 2026

📦 Binary Size-limit

Comparing 36e1f02 to fix(browser): update worker format and add e2e test (#12747) by CPunisher

❌ Size increased by 2.63KB from 47.99MB to 48.00MB (⬆️0.01%)

@JSerFeng JSerFeng force-pushed the vk/3359-css-sourceorder branch from a9e7615 to 36e1f02 Compare January 19, 2026 06:34
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 19, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing vk/3359-css-sourceorder (36e1f02) with main (5b35090)

Summary

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@JSerFeng JSerFeng merged commit 6991b7b into main Jan 19, 2026
77 of 79 checks passed
@JSerFeng JSerFeng deleted the vk/3359-css-sourceorder branch January 19, 2026 07:35
LingyuCoder pushed a commit that referenced this pull request Jan 21, 2026
* 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
chenjiahan pushed a commit that referenced this pull request Jan 21, 2026
* 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
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]: CSS Loading Order Regression: Mixed import and require Statements

2 participants