Skip to content

Ensure custom --spacing-* values don't shadow spacing utility keywords - #20394

Open
thejamesgore wants to merge 3 commits into
tailwindlabs:mainfrom
thejamesgore:fix/leading-none-spacing-shadow
Open

Ensure custom --spacing-* values don't shadow spacing utility keywords#20394
thejamesgore wants to merge 3 commits into
tailwindlabs:mainfrom
thejamesgore:fix/leading-none-spacing-shadow

Conversation

@thejamesgore

@thejamesgore thejamesgore commented Aug 6, 2026

Copy link
Copy Markdown

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 (#19722 (comment)) 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: 3remleading-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.

Signed-off-by: James Gore <83005220+thejamesgore@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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 91bc988 and d6d00df.

📒 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/tailwindcss/src/utilities.test.ts (1)

25736-25739: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover explicit --leading-none precedence.

Add --leading-none to this theme and assert that leading-none uses it. This locks the required primary-theme precedence over the static value.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9b38bd47-531e-49b4-9db1-8a68e7c2ca32

📥 Commits

Reviewing files that changed from the base of the PR and between e566a92 and 23391dd.

📒 Files selected for processing (2)
  • packages/tailwindcss/src/utilities.test.ts
  • packages/tailwindcss/src/utilities.ts

@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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

Signed-off-by: James Gore <83005220+thejamesgore@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v4] Custom named --spacing-* values shadow leading-none staticValues (e.g. --spacing-none: 0 causes line-height: 0)

1 participant