No description
Find a file
Robin Malfait b9449612ba
Canonicalization: do not canonicalize units in arbitrary values (#19988)
This PR improves the canonicalization when dealing with arbitrary
values.

As part of the canonicalization process we compute a signature for a
given utility. This way we can ensure that when we canonicalize a
candidate into a simpler candidate that it's still equivalent if the
signatures match.

One thing we do during signature computation is normalizing dimensions
(value + unit) into the same unit to make comparisons easier.

For example:
```css
.foo { margin-top: 20in; }
.bar { margin-top: 1920px; }
```

Will both get converted to `1920px` and therefore `foo` and `bar` will
have the same signature.

Up until this part, everything is fine. However, this normalization also
leaks when we try to canonicalize arbitrary values. One of the things we
do is try to move the `-` into the arbitrary value:
```diff
- -mt-[20in]
+ mt-[calc(20in_*_-1)]
```

This is obviously not cleaner, but we can perform some canonicalization
of the arbitrary value. As part of that we do constant folding _and_ the
normalization of base units. That means that we would see this:
```diff
- -mt-[20in]
- mt-[calc(20in_*_-1)]
+ mt-[-1920px]
```

But this might be very confusing because it might not make sense where
the `1920px` even came from... the only thing we should have done here
is constant fold that calc expression.

That's what this PR does, it only does the constant folding but without
the unit normalization:
```diff
- -mt-[20in]
- mt-[calc(20in_*_-1)]
+ mt-[-20in]
```

Which is exactly what we want!

Fixes:
https://github.com/tailwindlabs/tailwindcss-intellisense/issues/1573

## Test plan

1. Added a regression test based on the linked issue
2. All other tests still pass
2026-04-28 16:42:02 +02:00
.github Improve CI for NAPI-RS (#19983) 2026-04-26 19:37:28 +02:00
crates Bump NAPI related dependencies (#19982) 2026-04-26 17:49:06 +02:00
integrations Always resolve relative files, relative to the current .css file (#19965) 2026-04-24 15:07:56 +02:00
packages Canonicalization: do not canonicalize units in arbitrary values (#19988) 2026-04-28 16:42:02 +02:00
patches Bump Lightning CSS (#19771) 2026-03-18 15:57:52 +01:00
playgrounds Bump dependencies in playgrounds (#19954) 2026-04-23 12:51:20 +02:00
scripts Make TypeScript a bit more happy (#19124) 2025-10-14 19:52:46 +00:00
.gitignore Fix slow unit test (#17465) 2025-03-31 15:26:01 +02:00
.prettierignore Bump dependencies (#19608) 2026-02-04 12:38:50 +01:00
Cargo.lock Bump NAPI related dependencies (#19982) 2026-04-26 17:49:06 +02:00
Cargo.toml Hoist oxide/crates to just crates (#13333) 2024-03-23 09:00:48 -04:00
CHANGELOG.md Canonicalization: do not canonicalize units in arbitrary values (#19988) 2026-04-28 16:42:02 +02:00
LICENSE Add README, LICENSE, and CONTRIBUTING (#13088) 2024-03-05 14:45:39 -05:00
package.json Bump dependencies (#19957) 2026-04-24 21:21:12 +02:00
pnpm-lock.yaml Bump NAPI related dependencies (#19982) 2026-04-26 17:49:06 +02:00
pnpm-workspace.yaml Bump dependencies (#19957) 2026-04-24 21:21:12 +02:00
README.md docs: fix GitHub links to tailwindlabs org (#19686) 2026-02-17 13:06:49 +01:00
rust-toolchain.toml Bump NAPI related dependencies (#19982) 2026-04-26 17:49:06 +02:00
turbo.json Fix segmentation fault when loading @tailwindcss/oxide in a Worker thread (#17276) 2025-03-18 16:28:20 -04:00
vitest.config.ts Bump Vitest to v4 (#19216) 2025-11-20 18:16:20 -05:00

Tailwind CSS

A utility-first CSS framework for rapidly building custom user interfaces.

Build Status Total Downloads Latest Release License


Documentation

For full documentation, visit tailwindcss.com.

Community

For help, discussion about best practices, or feature ideas:

Discuss Tailwind CSS on GitHub

Contributing

If you're interested in contributing to Tailwind CSS, please read our contributing docs before submitting a pull request.