Skip to content

Improve canonicalization for bare values exceeding default spacing scale suggestions#19809

Merged
RobinMalfait merged 3 commits intomainfrom
feat/canonicalize-bare-value
Mar 16, 2026
Merged

Improve canonicalization for bare values exceeding default spacing scale suggestions#19809
RobinMalfait merged 3 commits intomainfrom
feat/canonicalize-bare-value

Conversation

@RobinMalfait
Copy link
Member

This PR adds support for canonicalization of utilities that accept bare values and exceed the default spacing scale we use for intellisense.

Right now, all utilities are behind functions, so the only way to know whether something compiles is by compiling a candidate, e.g. w-8 and passing it to the utility functions. To help us, we use the intellisense APIs that we use for suggestions.

Most utilities that accept bare values, have suggestions up until *-96, so w-96 h-96 would be canonicalized to size-96. But the moment we exceed that, the result stays as-is.

→ w-96 h-96
= size-96

→ w-1234 h-1234
= h-1234 w-1234

This PR ensures that the last scenario also gets canonicalized to size-1234 instead of staying as h-1234 w-1234.

→ w-96 h-96
= size-96

→ w-1234 h-1234
= size-1234

Test plan

  1. Existing tests pass
  2. Added new tests for utilities with bare values

[ci-all] just to see if this additional logic doesn't cause timeouts in CI for WIndows. In my testing this doesn't have a significant impact on performance at all.

By default we use intellisense' provided values which typically go up to
`96` by default. But since a lot of utilities accept bare values, we
still want to be able to collapse `w-1234 h-1234` into `size-1234`. This
code enables that.

We do loop over all functional utility functions, but we are only
interested in utilities that set one of the properties that the original
candidate also sets.

Otherwise all utilities that accept `*-1234` as a value would be in the
list, which is not what we want and will never match so it's unnecessary
work.
@RobinMalfait RobinMalfait requested a review from a team as a code owner March 16, 2026 21:28
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cfd7546d-5758-4e68-bd6d-2491c250a12f

📥 Commits

Reviewing files that changed from the base of the PR and between aaaefe8 and 6fe6556.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/tailwindcss/src/canonicalize-candidates.test.ts
  • packages/tailwindcss/src/canonicalize-candidates.ts

Walkthrough

This pull request enhances canonicalization functionality for Tailwind CSS utilities. A new dynamicUtilities mechanism is introduced in the canonicalize-candidates implementation to expand potential replacement utilities during collapse by computing property-value-to-replacement mappings. Test coverage is extended with cases validating the combination of arbitrary value utilities exceeding default spacing scales, such as converting w-123 h-123 to size-123. The CHANGELOG is updated to document this canonicalization improvement.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: improving canonicalization for bare values exceeding default spacing scale suggestions.
Description check ✅ Passed The description is directly related to the changeset, providing context, examples, and test plans for the canonicalization improvement for utilities with bare values.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

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

Tip

You can generate walkthrough in a markdown collapsible section to save space.

Enable the reviews.collapse_walkthrough setting to generate walkthrough in a markdown collapsible section.

@RobinMalfait RobinMalfait merged commit bb2f170 into main Mar 16, 2026
23 checks passed
@RobinMalfait RobinMalfait deleted the feat/canonicalize-bare-value branch March 16, 2026 21:44
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.

1 participant