Preserve zero spacing as a length in custom properties - #20317
Conversation
Confidence Score: 5/5Safe to merge — the change is a single conditional within the zero-value fast path; the non-custom-property branch is completely unmodified. The fix is minimal and well-targeted. The source.kind and source.property.startsWith('--') guard correctly identifies the only context where a unitless 0 is type-unsafe. All pre-existing tests for regular-property optimization continue to expect '0', confirming nothing regresses there. The single new test reproduces the reported failure mode end-to-end. The only open item is a stale inline comment that wasn't updated to describe the new dual behavior. No files require special attention — both changed files are small and self-contained. Reviews (1): Last reviewed commit: "Fix zero spacing in custom properties" | Re-trigger Greptile |
WalkthroughThe spacing() CSS function was updated so that when a resolved spacing value equals zero, it now returns "0px" when the value is being assigned to a custom property (a declaration whose property name starts with "--"), and continues to return "0" in other contexts. This required renaming an internal function parameter to make the declaration context accessible. A new test was added to verify that --spacing(0) assigned to a custom property preserves the "0px" form and behaves correctly when subsequently used in a calc() expression. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/tailwindcss/src/css-functions.ts (1)
66-73: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUpdate the optimization comment to reflect the new custom-property path.
Line 73 says "a value of
0can be replaced by0", but this is no longer universally true — custom property declarations now produce0px. A small comment update would keep the rationale accurate.📝 Suggested comment update
// - That means that a value of `0` can be replaced by `0` - // - That means that a value of `1` can be replaced by `multiplier` + // - That means that a value of `0` can be replaced by `0` (or `0px` for custom properties to preserve length type) + // - That means that a value of `1` can be replaced by `multiplier`
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5e43d0af-78b0-4fcd-ae23-3bc7a212ef6b
📒 Files selected for processing (2)
packages/tailwindcss/src/css-functions.test.tspackages/tailwindcss/src/css-functions.ts
|
Hey! Thanks for the PR, but I fixed it in a different way as part of #20319. Your PR does solve the issue where you use |
Summary
Fixes #20315.
--spacing(0)was optimized to unitless0even when assigned to a custom property. That changes the value type from a length to a number when the variable is later used incalc(), so this keeps direct declarations compact while emitting0pxfor custom-property assignments.Test plan
pnpm install --frozen-lockfilepnpm exec vitest run packages/tailwindcss/src/css-functions.test.ts --hideSkippedTestspnpm exec prettier --check packages/tailwindcss/src/css-functions.ts packages/tailwindcss/src/css-functions.test.tsI also ran the same Vitest command after adding the regression test but before the fix, and confirmed it failed with
--offset: 0instead of--offset: 0px.