Ensure custom --spacing-* values don't shadow spacing utility keywords
Fixes #19722
This has been open a while and the existing fix attempt went stale — it was created via an automated agent and is flawed IMO, so gave it a crack.
If you define a custom named spacing value like --spacing-none: 0, leading-none starts outputting line-height: 0 instead of line-height: 1.
The leading utility resolves theme values against ['--leading', '--spacing'] before it ever falls back to the static none keyword, so the custom spacing value wins the lookup and the keyword is never reached.
The fix splits a spacing utility's theme keys into its own namespaces and the generic --spacing fallback, and checks staticValues between the two. Setting --leading-none explicitly still overrides everything, which keeps the documented way of customising it working. leading is the only spacing utility that uses staticValues so nothing else changes behaviour.
Worth noting #19773 is the earlier attempt. I've scoped this one to just the spacing utilities rather than changing value resolution for every functional utility based on first key position, plus that PR had a few other issues — I left a comment on the thread (https://github.com/tailwindlabs/tailwindcss/issues/19722#issuecomment-5208892050) to have some discussion on the best approach.
For testing I added a new case to the leading test with --spacing-none: 0 and --spacing-big: 3rem — leading-none emits line-height: 1 and leading-big emits var(--spacing-big). It fails on main (you get line-height: var(--spacing-none)) and passes with the fix. The existing --leading-none: 2 override test is untouched and still green, and the full packages/tailwindcss suite passes locally.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 84d39638-30d5-4f82-9a9b-3dbf32bf0468
📥 Commits
Reviewing files that changed from the base of the PR and between 91bc988a0b9d6f3f2139da10f7dfa2fcef5082fb and d6d00dff654148ac751638eba7ce90403de3957e.
📒 Files selected for processing (1)
packages/tailwindcss/src/utilities.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/tailwindcss/src/utilities.test.ts
Walkthrough
Functional utilities now support fallback theme namespaces for resolution and suggestions. Static values take precedence over fallback matches. Spacing utilities use namespaces before --spacing as primary keys and namespaces from --spacing as fallback keys. Regression tests verify leading-big, built-in leading-none, and explicit --leading-none precedence.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly summarizes the primary fix: preventing custom spacing values from shadowing spacing utility keywords. |
| Description check | ✅ Passed | The description directly explains the reported bug, implementation, scope, and regression tests. |
| Linked Issues check | ✅ Passed | The changes address issue #19722 by preserving static keywords, spacing fallbacks, and explicit leading overrides. |
| Out of Scope Changes check | ✅ Passed | The implementation, regression tests, and changelog entry are directly related to the linked issue objectives. |
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 @coderabbitai help to get the list of available commands.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Reviews (3): Last reviewed commit: "Cover explicit --leading-none precedence..." | Re-trigger Greptile