Skip to content

fix: optimize CSS runtime requirements logic#12529

Merged
LingyuCoder merged 1 commit intomainfrom
fix/css-runtime-requirements-optimization
Dec 23, 2025
Merged

fix: optimize CSS runtime requirements logic#12529
LingyuCoder merged 1 commit intomainfrom
fix/css-runtime-requirements-optimization

Conversation

@LingyuCoder
Copy link
Copy Markdown
Contributor

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:

  • Refactored 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 ENSURE_CHUNK_HANDLERS or HMR_DOWNLOAD_UPDATE_HANDLERS are required
  • Fixed test cases to match expected behavior after the optimization

Checklist

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

- 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
Copilot AI review requested due to automatic review settings December 23, 2025 06:04
@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: bug fix release: bug related release(mr only) labels Dec 23, 2025
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 23, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 472d3c9
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/694a30f86114880008db93fc

Copy link
Copy Markdown
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 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_MODULES is required
  • Only add PUBLIC_PATH, GET_CHUNK_CSS_FILENAME, and HAS_OWN_PROPERTY when specifically needed by ENSURE_CHUNK_HANDLERS or HMR_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.

@github-actions
Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 823.4 KB 0
react-5k 2.7 MB 0
rome 984.3 KB 0
ui-components 2.1 MB -474.0 B (-0.0%)
📋 Detailed Reports (Click to expand)

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

📌 Baseline Commit: 4891406fea | PR: #12499

Metric Current Baseline Change
📊 Total Size 2.1 MB 2.1 MB -474.0 B (-0.0%)
📄 JavaScript 2.0 MB 2.0 MB -474.0 B (-0.0%)
🎨 CSS 83.0 KB 83.0 KB 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: ui-components Bundle Diff

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 472d3c9 to feat: add rspack_tools to compare .cache from different os (#12499) by jinrui

🙈 Size remains the same at 47.87MB

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 23, 2025

CodSpeed Performance Report

Merging #12529 will not alter performance

Comparing fix/css-runtime-requirements-optimization (472d3c9) with main (4891406)

Summary

✅ 16 untouched
⏩ 1 skipped1

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.

@LingyuCoder LingyuCoder requested a review from JSerFeng December 23, 2025 06:27
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 23, 2025

📝 Ecosystem CI detail: Open

suite result
rstest ✅ success
modernjs ❌ failure
lynx-stack ❌ failure
rsdoctor ✅ success
devserver ✅ success
rsbuild ✅ success
examples ✅ success
plugin ✅ success
rslib ❌ failure
nuxt ✅ success
rspress ✅ success

@LingyuCoder LingyuCoder merged commit 769e045 into main Dec 23, 2025
82 checks passed
@LingyuCoder LingyuCoder deleted the fix/css-runtime-requirements-optimization branch December 23, 2025 07:40
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.

3 participants