Always produce <length> value when optimizing --spacing(0) - #20319
Conversation
Otherwise `0` can result in a `<number>` type instead of a `<length>` type. With this, we ensure that it's always a number type.
Confidence Score: 5/5Safe to merge — single targeted fix with no side-effects on typed properties, all snapshot tests updated correctly. The fix is a one-line change that correctly resolves the No files require special attention. Reviews (2): Last reviewed commit: "update changelog" | Re-trigger Greptile |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughThis change updates the spacing(...) optimization to emit 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/tailwindcss/src/css-functions.test.ts (1)
110-117: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueLocal helper shadows imported
compileCss.The local
compileCsshere shadows thecompileCssimported from./test-utils/runat line 6, only within this describe block. Works correctly, but the identical naming makes it easy to lose track of which implementation is active when reading/editing this suite later.♻️ Suggested rename
- async function compileCss(css: string, options: Parameters<typeof compile>[1] = {}) { + async function compileCssWithoutLightning(css: string, options: Parameters<typeof compile>[1] = {}) { let { build } = await compile(css, options) return pretty(build([])) }And update call sites within this block accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fe18e76a-a653-4c6f-b264-2e2e0cf9e992
📒 Files selected for processing (3)
packages/tailwindcss/src/css-functions.test.tspackages/tailwindcss/src/css-functions.tspackages/tailwindcss/src/utilities.test.ts
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 value0instead ofcalc(var(--spacing) * 0)which is fine if you use it in a spot where a<length>data type can be used, then the0is interpreted as a<length>.E.g.:
padding: 0andpadding: 0pxare equivalent.However, if you use it in a CSS variable, then the
0will turn in a<number>if you don't have an@propertydefinition 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 usewidth: calc(100% --spacing(0)). This value is a bit silly anyway, but it would originally resolve tocalc(100% + calc(var(--spacing) * 0)), the optimization ofcalc(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 use0, but in the places we can't the0pxwould 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
0pxis still better than the longcalc(var(--spacing) * 0)value.Fixes: #20315
Closes: #20317
Test plan
--spacing(0)does produce0pxwhich has a length type