Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 29, 2025

Remove special logic for inserting spaces when removing comments. Instead, treat comments as equivalent to whitespace, and apply the same rules.

This fixes 2 problems:

  1. Don't add unnecessary space when a block comment appears after a character like {.
  2. Do add a space when a block comment is the whole quasi between 2 interpolations, to prevent them being merged.

Simplifying this logic also gives 1%-2% speed-up on transformer benchmarks.

Input:

styled.div`.a {/* blah */color: green; }`;
styled.div`${x}/* blah */${y}`;

Previous output post-minification:

styled.div`.a{ color:green;}`;
styled.div`${x}${y}`;

After this PR:

styled.div`.a{color:green;}`;
styled.div`${x} ${y}`;

@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Aug 29, 2025
Copy link
Member Author

overlookmotel commented Aug 29, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 29, 2025

CodSpeed Instrumentation Performance Report

Merging #13390 will degrade performances by 11.86%

Comparing 08-29-fix_transformer_styled-components_remove_unnecessary_whitespace_when_removing_block_comments_in_css_minification (cf5175c) with main (95d4311)1

Summary

❌ 1 regressions
✅ 37 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[cal.com.tsx] 3.4 ms 3.8 ms -11.86%

Footnotes

  1. No successful run was found on main (cf5175c) during the generation of this report, so 95d4311 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel marked this pull request as ready for review August 29, 2025 12:18
Copilot AI review requested due to automatic review settings August 29, 2025 12:18
@overlookmotel overlookmotel requested a review from Dunqing as a code owner August 29, 2025 12:18
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 fixes CSS minification issues in the styled-components transformer related to block comment handling. It removes unnecessary spaces when removing block comments after certain characters while preserving necessary spaces when comments separate interpolations.

  • Simplifies comment removal logic by treating comments as whitespace
  • Fixes unnecessary space insertion after characters like { when removing comments
  • Ensures proper spacing between interpolations when comments are the only content between them

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_transformer/src/plugins/styled_components.rs Refactored comment removal logic to use insert_space_if_required function consistently
tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-comments/input.js Added test cases with comments after { character
tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-comments/output.js Updated expected output to show proper minification without unnecessary spaces

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 30, 2025

Merge activity

…n removing block comments in CSS minification (#13390)

Remove special logic for inserting spaces when removing comments. Instead, treat comments as equivalent to whitespace, and apply the same rules.

This fixes 2 problems:

1. Don't add unnecessary space when a block comment appears after a character like `{`.
2. *Do* add a space when a block comment is the whole quasi between 2 interpolations, to prevent them being merged.

Simplifying this logic also gives 1%-2% speed-up on transformer benchmarks.

Input:

```js
styled.div`.a {/* blah */color: green; }`;
styled.div`${x}/* blah */${y}`;
```

Previous output post-minification:

```js
styled.div`.a{ color:green;}`;
styled.div`${x}${y}`;
```

After this PR:

```js
styled.div`.a{color:green;}`;
styled.div`${x} ${y}`;
```
@graphite-app graphite-app bot force-pushed the 08-29-fix_transformer_styled-components_remove_unnecessary_whitespace_when_removing_block_comments_in_css_minification branch from ac79d7a to cf5175c Compare August 30, 2025 04:24
@graphite-app graphite-app bot merged commit cf5175c into main Aug 30, 2025
24 checks passed
@graphite-app graphite-app bot deleted the 08-29-fix_transformer_styled-components_remove_unnecessary_whitespace_when_removing_block_comments_in_css_minification branch August 30, 2025 04:29
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants