mirror of
https://github.com/hanzoai/tailwindcss.git
synced 2026-09-24 17:03:14 +00:00
9183dbbed627bb6035e1c11d188ece94929b2fc0
<length> value when optimizing --spacing(0) (#20319)
This PR fixes a type issue when using `--spacing(0)`. This construction doesn't really make sense, but if you use it, it produces the value `0` instead of `calc(var(--spacing) * 0)` which is fine if you use it in a spot where a `<length>` data type can be used, then the `0` is interpreted as a `<length>`. E.g.: `padding: 0` and `padding: 0px` are equivalent. However, if you use it in a CSS variable, then the `0` will turn in a `<number>` if you don't have an `@property` definition for that CSS variable. This on its own isn't the issue, but if you later use it as part of a `calc(…)` then the `<number>` instead of `<length>` type is being used. As seen in #20315. We could remove the optimization, and use `calc(var(--spacing) * 0)` again, but this is a bit silly since it only makes your CSS file larger. We could try to be smart, and only do it _if_ we're assigning to a CSS variable (which #20317 is doing). But if your CSS variable _does_ use a `<length>` then it's a non-issue. We would run into the same issue if you use `width: calc(100% --spacing(0))`. This value is a bit silly anyway, but it would originally resolve to `calc(100% + calc(var(--spacing) * 0))`, the optimization of `calc(100% - 0)` would make it invalid, so the fix in #20317 would not be enough. Instead I opted for an inbetween solution, by always using `0px`. In most cases we can use `0`, but in the places we can't the `0px` would at least ensure that we are dealing with `<length>` data types. This way we don't have to try to be smart to analyze where we use the value, and `0px` is still better than the long `calc(var(--spacing) * 0)` value. Fixes: #20315 Closes: #20317 ## Test plan 1. Manually tested that now `--spacing(0)` does produce `0px` which has a length type
A utility-first CSS framework for rapidly building custom user interfaces.
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.
Languages
TypeScript
81.9%
Rust
15.7%
JavaScript
0.8%
CSS
0.6%
HTML
0.6%
Other
0.4%