Skip to content

Ensure --alpha(…) is seen as a color, and --spacing(…) is seen as a length#20260

Merged
RobinMalfait merged 5 commits into
mainfrom
fix/issue-20258
Jun 18, 2026
Merged

Ensure --alpha(…) is seen as a color, and --spacing(…) is seen as a length#20260
RobinMalfait merged 5 commits into
mainfrom
fix/issue-20258

Conversation

@RobinMalfait

@RobinMalfait RobinMalfait commented Jun 18, 2026

Copy link
Copy Markdown
Member

This PR fixes an issue where intellisense recommends this canonicalization:

- text-[calc(var(--spacing)*4)]
+ text-[--spacing(4)]

Which is correct, but the issue is that the result is different due to ambiguity of the text-* utilities.

.text-\[calc\(var\(--spacing\)\*4\)\] {
  font-size: calc(var(--spacing) * 4);
}
.text-\[--spacing\(4\)\] {
  color: calc(var(--spacing, 0.25rem) * 4);
}

Notice that we're using color all of a sudden? This is because that's the default and we infer the data type based on the arbitrary value. The calc(…) infers that the type is length, but we don't know what the type of --spacing(…) is so we fallback to the default type which would be color.

This PR makes sure that built in functions like --alpha(…) and --spacing(…) are resolved as color and length respectively.

With this fix in place, this is the result:

.text-\[calc\(var\(--spacing\)\*4\)\] {
  font-size: calc(var(--spacing) * 4);
}
.text-\[--spacing\(4\)\] {
  font-size: calc(var(--spacing, 0.25rem) * 4);
}

Fixes: #20256
Fixes: #20258

Test plan

  1. Added a regression test to make sure this doesn't happen anymore

@RobinMalfait RobinMalfait requested a review from a team as a code owner June 18, 2026 12:47
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The change is minimal and surgical — two small regex additions, each directly tested with snapshot assertions covering the previously-broken cases.

Both --alpha and --spacing are the only built-in Tailwind CSS functions with a well-defined return type (color and length respectively); the third built-in, --theme, is intentionally left out because it is type-agnostic. The fix is consistent with the existing patterns in both files and the regression tests confirm the corrected CSS output.

No files require special attention.

Reviews (2): Last reviewed commit: "update changelog" | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Two data-type recognizer functions are updated to correctly classify custom CSS function values. In infer-data-type.ts, a new IS_LENGTH_FN regex is added so that isLength returns true for var(--spacing)(...)-style values. In is-color.ts, the IS_COLOR_FN regex is extended to include the --alpha( prefix, making isColor return true for those values. Test snapshots are extended with text-[--spacing(2)] (generating font-size) and text-[--alpha(red/20%)] (generating color), and a changelog entry is added.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main changes: recognizing --alpha(...) as a color function and --spacing(...) as a length function.
Linked Issues check ✅ Passed The PR fully addresses both linked issues (#20256, #20258) by making --spacing(...) resolve as a length type, ensuring text-[--spacing(n)] generates font-size instead of color.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the data type inference issue: test updates, is-color.ts for --alpha(...), infer-data-type.ts for --spacing(...), and changelog entry.
Description check ✅ Passed The description clearly explains the issue, the root cause of type inference ambiguity, the solution, and provides concrete before/after examples showing how the fix resolves the problem.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/tailwindcss/src/utils/math-operators.ts`:
- Line 39: The issue is that in the addWhitespaceAroundMathOperators function,
the function-name scanner at lines 95-99 strips hyphens from function names,
causing --spacing( to be parsed as spacing instead of --spacing. When the code
checks MATH_FUNCTIONS.includes(fn) at line 107, it fails to match because it's
checking for spacing instead of --spacing. To fix this, modify the function-name
checking logic in addWhitespaceAroundMathOperators to also check for the
hyphenated version of custom properties (like --spacing) against MATH_FUNCTIONS,
either by preserving the original function name with hyphens before the check or
by adding both the stripped and hyphenated versions to the includes check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e9c54fb2-ff61-41ef-a75e-48dc69bbb662

📥 Commits

Reviewing files that changed from the base of the PR and between 34c2b04 and 9ae165b.

📒 Files selected for processing (3)
  • packages/tailwindcss/src/utilities.test.ts
  • packages/tailwindcss/src/utils/is-color.ts
  • packages/tailwindcss/src/utils/math-operators.ts

Comment thread packages/tailwindcss/src/utils/math-operators.ts Outdated
@RobinMalfait RobinMalfait merged commit c46f654 into main Jun 18, 2026
9 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-20258 branch June 18, 2026 13:02
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.

Resolves text-[--spacing(n)] as color instead of font-size Resolves text-[--spacing(n)] as color instead of font-size

1 participant