Skip to content

css: keep translate, rotate and scale apart from transform - #45210

Merged
Jarred-Sumner merged 1 commit into
mainfrom
robobun/54b4ba47/css-individual-transforms
Oct 14, 2026
Merged

Jarred-Sumner merged 1 commit into
mainfrom
robobun/54b4ba47/css-individual-transforms

Conversation

@robobun

@robobun robobun commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Problem

  • In one rule, the CSS minifier drops translate, rotate and scale declared before transform, and appends those declared after it to the transform list. .a{translate:10px;transform:rotate(10deg)} prints .a{transform:rotate(10deg)}. .a{transform:rotate(10deg);translate:10px} prints .a{transform:rotate(10deg)translate(10px)}.
  • The cause is TransformHandler::handle_property. The transform arm clears the three slots (src/css/properties/transform.rs:1021), and individual_property! pushes onto a buffered transform (:987).

Fix

  • Each of the four properties keeps its own slot. This is a port of fix: preserve individual transform properties parcel-bundler/lightningcss#1340.
  • The three to_transform helpers lose their only caller. The change removes them.
  • Correct because a browser composes the four in a fixed order, whatever the declaration order. Another rule can override one of them alone.
  • Verified: test/js/bun/css/css.test.ts (24 cases fail on main). Also test/bundler/css and test/bundler/esbuild/css.test.ts. Self-reviewed: 1 concern raised, 1 addressed (Notes).

Background

  • A handler buffers the declarations of one property group while the minifier walks a rule. flush prints them.
  • translate, rotate and scale are separate properties (CSS Transforms Level 2). They are not longhands of transform.
  • Considered a fold of the three into transform in the right order (the old TODO in the tests). It is wrong when another rule overrides one property, so upstream dropped it too.

Downsides

  • A rule with transform and one of the three now prints each declaration. The folded output was shorter. 0 of 4,929 real stylesheets change.
  • None found for size and speed. Release .text shrinks by 1,024 B. bun_css runs 2,760 fewer instructions over the 15 in-tree stylesheets.
Notes

Reproduce

printf '.a{translate:10px;transform:rotate(10deg)}\n.b{transform:rotate(10deg);translate:10px}\n.c{transform:none;translate:none}\n' > a.css
bun build a.css --minify
  • main: .a{transform:rotate(10deg)}.b{transform:rotate(10deg)translate(10px)}.c{transform:translate(0,0)}
  • this PR: .a,.b{transform:rotate(10deg);translate:10px}.c{transform:none;translate:none}

The result does not depend on browser targets. On main, .a loses the translation, .b translates along the rotated axis (the source translates along the page axis), and .c sets a transform where the source sets none.

Upstream

Existing expectations

Two existing expectations in the transform block change, and one commented-out case is active again:

  • translate: calc(50% - 100px + 20px) 0px; transform: translate(2px, 3px) now keeps translate.
  • scale: 0.5; transform: scale(3) now keeps scale.
  • transform: scale(3); scale: 0.5 prints transform:scale(3);scale:.5.

Measurements

  • Two release builds (bun run build:release) of 772f87f, with and without this change to src/css. Main has no src/css change between that commit and the merge base.
  • .text: 79,755,685 B to 79,754,661 B. The one symbol that changes is TransformHandler::handle_property: 2,397 B to 1,446 B.
  • Instructions inside the address ranges of the bun_css symbols, for one pass over the 15 stylesheets (45,894 declarations): 581,796,845 to 581,794,085. Counted from a qemu-x86_64 -d exec,nochain log, weighted by the instructions of each translation block. perf and valgrind are not available on the machine.
  • Stylesheets: every .css file of 175 npm packages (4,914 files) and the 15 in test/js/bun/css/files, with the default browser targets and with no targets. No output changes.

Suites

  • test/js/bun/css/css.test.ts: 1,314 pass, 0 fail. On main: 24 fail.
  • The other files in test/js/bun/css, test/bundler/css, test/bundler/esbuild/css.test.ts and the CSS regression tests 25785, 25794 and 27458 pass on the debug build, with one exception: two tests in nested-selector-expansion.test.ts hit the 5 s timeout. They do the same on a debug build of main.
  • Not run: css-fuzz.test.ts and nested-vendor-prefix-duplication.test.ts. Both time out on a debug build of main.

Port of parcel-bundler/lightningcss#1340.

The handler appended an individual transform property declared after
`transform` to the function list of `transform`, and dropped the ones
declared before it. Both change the result: the individual properties
cascade on their own and compose in a fixed order.

  transform: scale(3); scale: 0.5   was  transform:scale(3)scale(.5)
  scale: 0.5; transform: scale(3)   was  transform:scale(3)
  transform: none; translate: none  was  transform:translate(0,0)

Each property now keeps its own slot. The three `to_transform` helpers
lose their only caller and are removed.

Co-authored-by: Cong-Cong Pan <dacongsama@live.com>
@robobun

robobun commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 9:57 PM PT - Oct 13th, 2026

✅ @robobun, your commit b257a67ffdd79ecd6d756cc9a4bb22bda8c2fd46 passed in Build #125318! 🎉


🧪   To try this PR locally:

bunx bun-pr 45210

That installs a local version of the PR into your bun-45210 executable, so you can run:

bun-45210 --bun

@robobun

robobun commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status

Reproduced with a release build of main at 772f87f. src/css is the same at the merge base 281698a.

printf '.a{translate:10px;transform:rotate(10deg)}\n.b{transform:rotate(10deg);translate:10px}\n' > a.css
bun build a.css --minify
  • main prints .a{transform:rotate(10deg)}.b{transform:rotate(10deg)translate(10px)}.
  • This PR prints .a,.b{transform:rotate(10deg);translate:10px}.

test/js/bun/css/css.test.ts has 24 failing cases on main and none with this PR.

PR: #45210

@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: oven-sh/bun/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ce10f5f9-024c-4627-a6e3-15b6ac48166d
📥 Commits

Reviewing files that changed from the base of the PR and between 177da66 and b257a67.

📒 Files selected for processing: 3
  • src/css/properties/transform.rs
  • test/js/bun/css/css.test.ts
  • test/js/bun/css/util.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Walkthrough

TransformHandler now stores translate, rotate, and scale separately from transform declarations and flushes them separately. CSS tests cover declaration ordering, resets, identity values, importance, custom properties, and vendor prefixes. A helper registers TODO comparisons.

Changes

CSS Transform Properties

Layer / File(s) Summary
Store individual transform properties
src/css/properties/transform.rs
TransformHandler stores translate, rotate, and scale in separate fields. Handling a transform declaration no longer clears those individual properties. Conversion helpers for the individual properties were removed.
Validate transform declaration output
test/js/bun/css/css.test.ts, test/js/bun/css/util.ts
Tests cover declaration ordering, resets, identity values, importance, custom-property values, and vendor prefixes. The test utility adds cssTestTodo for TODO comparisons.

Suggested reviewers: jarred-sumner

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to b257a

The transform-property change is mergeable after normal checks. The rotate identity cases remain documented TODOs rather than active regression tests.

Pre-merge checks: Passed 4
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: keeping the individual CSS transform properties separate from transform.
Description check Passed The description clearly explains the problem, implementation, rationale, impact, and verification results. It does not use the exact template headings, but it provides the required information for wha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

@Jarred-Sumner
Jarred-Sumner merged commit 3da4e25 into main Oct 14, 2026
11 of 12 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the robobun/54b4ba47/css-individual-transforms branch October 14, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants