Skip to content

Unescape theme keys in the color-mix(…) polyfill - #20735

Open
RobinMalfait wants to merge 1 commit into
mainfrom
robin/unescape-theme-keys-in-the-color-mix-polyfill
Open

RobinMalfait wants to merge 1 commit into
mainfrom
robin/unescape-theme-keys-in-the-color-mix-polyfill

Conversation

@RobinMalfait

Copy link
Copy Markdown
Contributor

This PR fixes the color-mix(…) polyfill for theme colors with escaped characters in their name.

The polyfill looks up the variable of a var(…) in the theme to inline its color in the fallback. The value parser keeps CSS escapes in the variable name (e.g. --color-brand\.light), but the theme stores its keys unescaped (--color-brand.light). So the lookup missed, and the fallback lost its opacity:

@theme {
  --color-brand\.light: oklch(63.7% 0.237 25.331);
}
@tailwind utilities;

text-brand.light/50 generated:

.text-brand\.light\/50 {
  color: var(--color-brand\.light);
}

Now it generates:

.text-brand\.light\/50 {
  color: #fb2c3680;
}

The fix unescapes the variable name before the lookup, as Theme#markUsedVariable and Theme#getOptions already do.

Conflict with #20606

#20606 changes the same line, to designSystem.theme.unprefixKey(variableName). Whichever PR merges second has a small conflict there. The final form is:

designSystem.theme.resolveValue(null, [unescape(designSystem.theme.unprefixKey(variableName)) as any])

Test plan

  • Added a test with --color-brand\.light and --color-1\.5: var(--color-brand\.light), which also covers an escaped name in a nested var(…). It fails without the fix.
  • pnpm vitest run in packages/tailwindcss passes.

The value parser keeps CSS escapes in variable names, e.g.
`--color-brand\.light`, but the theme stores its keys unescaped. The
lookup missed, and the fallback before `@supports (color: color-mix(…))`
lost its opacity.
@RobinMalfait
RobinMalfait requested a review from a team as a code owner November 20, 2026 15:39
@RobinMalfait RobinMalfait self-assigned this Nov 20, 2026
@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Reviews (1) · Last reviewed commit: "Unescape theme keys in the `color-mix(…)..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The color-mix fallback resolver now unescapes CSS variable names before looking them up in the theme. A regression test covers opacity utilities with escaped-dot theme keys, including a key that references another key. The changelog records the fix.

Merge Risk: Minimal · up to df01e

This fixes the color-mix fallback losing opacity for theme keys with escaped characters. No remaining merge-blocking risk was found. Prefixed themes still have a separate pre-existing gap that PR #20606 covers.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the color-mix() polyfill now unescapes theme keys before lookup. It matches the changeset in ast.ts and the new regression test. It is concise and specific.
Description check Passed The description explains the bug, the cause (escaped variable names from the value parser versus unescaped theme keys), and the fix in the color-mix() polyfill lookup. It also gives a test plan. This …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the bug, the cause (escaped variable names from the value parser versus unescaped theme keys), and the fix in the color-mix() polyfill lookup. It also gives a test plan. This matches the changes in ast.ts, the changelog, and the test file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 319f3a1b-ebb4-4d95-a88c-2e4658c2408e
Commits

Reviewing files that changed from the base of the PR and between 92010c6 and df01eb2.

Files selected for processing: 3

  • .changelog/color-mix-polyfill-escaped-theme-keys.md
  • packages/tailwindcss/src/ast.ts
  • packages/tailwindcss/src/index.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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.

1 participant