Skip to content

Comments

feat(rolldown_plugin_vite_css_post): implement cssScopeTo for scoped CSS tree-shaking#7240

Merged
graphite-app[bot] merged 1 commit intomainfrom
11-27-feat_rolldown_plugin_vite_css_post_implement_cssscopeto_for_scoped_css_tree-shaking
Nov 28, 2025
Merged

feat(rolldown_plugin_vite_css_post): implement cssScopeTo for scoped CSS tree-shaking#7240
graphite-app[bot] merged 1 commit intomainfrom
11-27-feat_rolldown_plugin_vite_css_post_implement_cssscopeto_for_scoped_css_tree-shaking

Conversation

@shulaoda
Copy link
Member

No description provided.

Copy link
Member Author

shulaoda commented Nov 27, 2025


How to use the Graphite Merge Queue

Add the label graphite: merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@shulaoda shulaoda changed the title feat(rolldown_plugin_vite_css_post): implement cssScopeTo for scoped CSS tree-shaking feat(rolldown_plugin_vite_css_post): implement cssScopeTo for scoped CSS tree-shaking Nov 27, 2025
@shulaoda shulaoda marked this pull request as ready for review November 27, 2025 10:10
Copilot AI review requested due to automatic review settings November 27, 2025 10:10
@netlify
Copy link

netlify bot commented Nov 27, 2025

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 488d8d0
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6929097feb12cb0008783b2d
😎 Deploy Preview https://deploy-preview-7240--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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 implements scoped CSS tree-shaking functionality by adding a cssScopeTo callback mechanism. The feature enables the Vite CSS post-processing plugin to determine which CSS modules should be included in the final bundle based on whether their associated importer module's exports are actually rendered in the output chunks.

Key Changes:

  • Added getModuleOptions method to TypeScript PluginContext API for accessing module metadata
  • Introduced cssScopeTo callback in the Vite CSS post plugin configuration that returns a mapping of CSS module IDs to their importer and export dependencies
  • Implemented CSS scope checking logic in the render_chunk hook to skip bundling CSS when its associated exports aren't rendered

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/rolldown/src/plugin/plugin-context.ts Added getModuleOptions method to PluginContext interface and implementation to expose module options
packages/rolldown/src/binding.d.cts Added TypeScript type declaration for cssScopeTo callback function in BindingViteCssPostPluginConfig
crates/rolldown_plugin_vite_css_post/src/lib.rs Removed Default derive, added css_scope_to field, integrated CSS scope checking logic in render_chunk to filter CSS based on rendered exports
crates/rolldown_plugin_utils/src/constants.rs Added CSSScopeToMap struct to store the mapping between CSS modules and their scope information
crates/rolldown_binding/src/options/plugin/config/binding_vite_css_post_plugin_config.rs Added css_scope_to field to binding config and conversion logic from JS callback to Rust async function
crates/rolldown_binding/src/options/plugin/binding_builtin_plugin.rs Made ViteCSSPost plugin options mandatory, returning an error if options are missing instead of using Default

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2025

Benchmarks Rust

  • target: main(f46e1d6)
  • pr: 11-27-feat_rolldown_plugin_vite_css_post_implement_cssscopeto_for_scoped_css_tree-shaking(488d8d0)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     68.0±2.96ms        ? ?/sec    1.00     68.2±2.25ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     76.9±4.06ms        ? ?/sec    1.00     76.9±3.08ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    110.3±2.92ms        ? ?/sec    1.01    111.9±3.59ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    122.2±2.42ms        ? ?/sec    1.02    124.2±2.45ms        ? ?/sec
bundle/bundle@threejs                                        1.00     40.7±1.31ms        ? ?/sec    1.00     40.8±0.94ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     44.2±0.80ms        ? ?/sec    1.02     44.9±1.05ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    402.3±8.34ms        ? ?/sec    1.00    402.0±7.02ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    461.7±6.12ms        ? ?/sec    1.01    467.0±7.77ms        ? ?/sec
scan/scan@rome_ts                                            1.00     87.7±2.14ms        ? ?/sec    1.02     89.5±2.76ms        ? ?/sec
scan/scan@threejs                                            1.00     29.6±0.56ms        ? ?/sec    1.02     30.2±0.88ms        ? ?/sec
scan/scan@threejs10x                                         1.00    303.7±5.87ms        ? ?/sec    1.02    309.8±5.32ms        ? ?/sec

@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 28, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 11-27-feat_rolldown_plugin_vite_css_post_implement_cssscopeto_for_scoped_css_tree-shaking branch from 7edcbf6 to 488d8d0 Compare November 28, 2025 02:31
@graphite-app graphite-app bot merged commit 488d8d0 into main Nov 28, 2025
28 checks passed
@graphite-app graphite-app bot deleted the 11-27-feat_rolldown_plugin_vite_css_post_implement_cssscopeto_for_scoped_css_tree-shaking branch November 28, 2025 02:45
IWANABETHATGUY pushed a commit that referenced this pull request Nov 28, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Nov 28, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Nov 29, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Nov 30, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Nov 30, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Nov 30, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Nov 30, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Nov 30, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Nov 30, 2025
IWANABETHATGUY pushed a commit that referenced this pull request Dec 1, 2025
This was referenced Dec 3, 2025
shulaoda added a commit that referenced this pull request Dec 3, 2025
## [1.0.0-beta.53] - 2025-12-03

💥 Breaking Changes
- Drop `i686-pc-windows-msvc` target support

🚀 Chunk Merging Optimization
- Rolldown now automatically merges shared chunks when entries import each other (when `preserveEntrySignature` is not `strict`)
```shell
Before:
entry.js   → imports → shared.js (common chunk)
entry2.js  → imports → shared.js
Output: 3 chunks (entry.js, entry2.js, shared.js)

After:
entry.js   → contains shared code
entry2.js  → imports → entry.js
Output: 2 chunks (entry.js, entry2.js)
```

### 💥 BREAKING CHANGES

- drop `i686-pc-windows-msvc` target support (#7230) by @sapphi-red

### 🚀 Features

- rolldown_plugin_vite_manifest: pass normalized options to `isLegacy` callback (#7321) by @shulaoda
- plugin/vite-resolve: add `disableCache` option (#6763) by @sapphi-red
- rolldown: export `createTokioRuntime` for tsdown (#7264) by @shulaoda
- rolldown_plugin_vite_html: sync `moduleSideEffects` for already loaded modules (#7254) by @shulaoda
- rolldown_plugin_vite_html: load module scripts with side effects to prevent tree-shaking (#7244) by @shulaoda
- rolldown_plugin_vite_css_post: implement `cssScopeTo` for scoped CSS tree-shaking (#7240) by @shulaoda

### 🐛 Bug Fixes

- export default class decl __name runtime insertion (#7316) by @IWANABETHATGUY
- chunk side effects calculation (#7273) by @IWANABETHATGUY
- node: `output.generateCode.preset: 'es2015'` should set `output.generateCode.symbols: true` by default (#7314) by @sapphi-red
- skip name helper for classes with static name property (#7312) by @IWANABETHATGUY
- preserve chunk imports relationship after chunk merging (#7303) by @shulaoda
- dev: make `register_modules` async (#7289) by @hyf0
- preserve computed property in object destructuring (#7288) by @IWANABETHATGUY
- support dynamic imports with shared dependencies (#7261) by @IWANABETHATGUY
- call `defer_sync_scan_data` in non-incremental build mode (#7255) by @shulaoda
- optimize chunk merging for shared entry points (#7194) by @IWANABETHATGUY
- add indentation for UMD format output (#7263) by @IWANABETHATGUY
- rolldown_plugin_vite_css_post: pass options to `isLegacy` callback for proper legacy detection (#7260) by @shulaoda
- rolldown_plugin_vite_css_post: also detect `?inline=true` query for inlined CSS (#7245) by @shulaoda
- rolldown_plugin_vite_css_post: distinguish empty CSS from no CSS (#7241) by @shulaoda
- add Windows support for t-run command (#7242) by @IWANABETHATGUY
- cjs: prevent duplicate require declarations for external modules with preserveModules (#7234) by @logaretm
- rolldown_plugin_vite_resolve: resolve from root for virtual modules (#7236) by @sapphi-red
- include entry level external modules in chunk exports (#7218) by @IWANABETHATGUY

### 🚜 Refactor

- dev: make `removeClient` async (#7313) by @hyf0
- move chunk merging code out of code_splitting.rs (#7285) by @IWANABETHATGUY
- extract common function util for chunk merging (#7271) by @IWANABETHATGUY
- use iterative method to merge chunks (#7256) by @IWANABETHATGUY
- use concat_string! instead of string replace for generating chunk level exports (#7247) by @IWANABETHATGUY

### 📚 Documentation

- add warning to experimental.resolveNewUrlToAsset about JS/TS files (#7300) by @Copilot
- add sequential hook execution difference in plugin-api.md (#7308) by @Copilot
- add migration example from onwarn to onLog (#7299) by @Copilot
- add migration example for manualChunks to advancedChunks (#7298) by @Copilot
- deps: bump vitepress to fix build (#7307) by @sapphi-red
- examples & text for experimental.resolveNewUrlToAsset (#7259) by @TheAlexLichter

### ⚡ Performance

- rolldown_plugin_vite_css_post: lazily load `cssScopeTo` from JS module options (#7253) by @shulaoda
- rolldown_plugin_vite_css_post: avoid unnecessary string clones in `resolve_asset_urls_in_css` (#7250) by @shulaoda

### 🧪 Testing

- generate relative path like name in advanced chunks (#7267) by @IWANABETHATGUY
- add test case for preserveEntrySignatures with re-exports (#7279) by @IWANABETHATGUY
- add test262 integration tests (#7196) by @sapphi-red

### ⚙️ Miscellaneous Tasks

- deps: update dependency rolldown-plugin-dts to v0.18.1 (#7304) by @renovate[bot]
- enable tracing feature for napi (#7322) by @sapphi-red
- deps: update napi (#7320) by @renovate[bot]
- deps: update oxc (#7318) by @renovate[bot]
- deps: update napi (#7317) by @renovate[bot]
- deps: update oxc to v0.100.0 (#7301) by @renovate[bot]
- deps: downgrade pnpm to 10.23.0 to fix Netlify build (#7306) by @shulaoda
- add `trustPolicyExclude` for chokidar and semver (#7302) by @sapphi-red
- update pnpm lockfile (#7291) by @IWANABETHATGUY
- deps: update npm packages (#7272) by @renovate[bot]
- deps: update rust crates (#7270) by @renovate[bot]
- deps: update oxc (#7262) by @renovate[bot]
- deps: update github-actions (#7269) by @renovate[bot]
- deps: update dependency dprint-typescript to v0.95.13 (#7268) by @renovate[bot]
- deps: update `html5gum` to 0.8.1 (#7265) by @shulaoda
- rolldown: remove unused `getModuleOptions` from `PluginContext` (#7266) by @shulaoda
- remove unnecessary justfile ignore (#7243) by @IWANABETHATGUY
- deps: update oxc apps (#7238) by @renovate[bot]
- add `nul` to workaround https://github.com/anthropics/claude-c… (#7237) by @IWANABETHATGUY
- deps: update dependency valibot to v1.2.0 [security] (#7231) by @renovate[bot]
- deps: update crate-ci/typos action to v1.40.0 (#7232) by @renovate[bot]

### ❤️ New Contributors

* @logaretm made their first contribution in [#7234](#7234)

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants