Skip to content

Make polyfill work when the theme variable resolves to another var#17562

Merged
RobinMalfait merged 2 commits intomainfrom
fix/color-mix-recursion
Apr 7, 2025
Merged

Make polyfill work when the theme variable resolves to another var#17562
RobinMalfait merged 2 commits intomainfrom
fix/color-mix-recursion

Conversation

@philipp-spiess
Copy link
Contributor

@philipp-spiess philipp-spiess commented Apr 4, 2025

Discovered while triaging #17556

This PR improves the color-mix(...) polyfill to ensure it works when a theme key links to another theme key via a var(...) call.

Imagine this setup:

 @theme { --color-red: var(--color-red-500); --color-red-500: oklch(63.7% 0.237 25.331); } @source inline("text-red/50");

Since --color-red will link to --color-red-500 which is also a known theme variable, we can inline the value of --color-red-500 into the fallback now:

.text-red\\/50 { color: var(--color-red); } @supports (color: color-mix(in lab, red, red)) { .text-red\\/50 { color: color-mix(in oklab, var(--color-red) 50%, transparent); } }

This will allow for slightly less confusing behavior.

The code added also handles recursive definitions where a color is linking to another color that is again linking to the first one (by adding a Set to keep track of already seen variable names).

Test plan

  • Added unit test
@RobinMalfait RobinMalfait force-pushed the fix/color-mix-recursion branch from 8508642 to 91f533b Compare April 7, 2025 09:26
@RobinMalfait RobinMalfait merged commit 3e9cf87 into main Apr 7, 2025
7 checks passed
@RobinMalfait RobinMalfait deleted the fix/color-mix-recursion branch April 7, 2025 09:42
vaernion pushed a commit to Arbeidstilsynet/brevgen2 that referenced this pull request Dec 3, 2025
…patch) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@tailwindcss/postcss](https://tailwindcss.com) ([source](https://github.com/tailwindlabs/tailwindcss/tree/HEAD/packages/@tailwindcss-postcss)) | [`4.1.3` -> `4.1.4`](https://renovatebot.com/diffs/npm/@tailwindcss%2fpostcss/4.1.3/4.1.4) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@tailwindcss%2fpostcss/4.1.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@tailwindcss%2fpostcss/4.1.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@tailwindcss%2fpostcss/4.1.3/4.1.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@tailwindcss%2fpostcss/4.1.3/4.1.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | | [tailwindcss](https://tailwindcss.com) ([source](https://github.com/tailwindlabs/tailwindcss/tree/HEAD/packages/tailwindcss)) | [`4.1.3` -> `4.1.4`](https://renovatebot.com/diffs/npm/tailwindcss/4.1.3/4.1.4) | [![age](https://developer.mend.io/api/mc/badges/age/npm/tailwindcss/4.1.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/tailwindcss/4.1.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/tailwindcss/4.1.3/4.1.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/tailwindcss/4.1.3/4.1.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>tailwindlabs/tailwindcss (@&#8203;tailwindcss/postcss)</summary> ### [`v4.1.4`](https://github.com/tailwindlabs/tailwindcss/blob/HEAD/CHANGELOG.md#414---2025-04-14) [Compare Source](tailwindlabs/tailwindcss@v4.1.3...v4.1.4) ##### Added - Add experimental `@tailwindcss/oxide-wasm32-wasi` target for running Tailwind in browser environments like StackBlitz ([#&#8203;17558](tailwindlabs/tailwindcss#17558)) ##### Fixed - Ensure `color-mix(…)` polyfills do not cause used CSS variables to be removed ([#&#8203;17555](tailwindlabs/tailwindcss#17555)) - Ensure `color-mix(…)` polyfills create fallbacks for theme variables that reference other theme variables ([#&#8203;17562](tailwindlabs/tailwindcss#17562)) - Fix brace expansion in declining ranges like `{10..0..5}` and `{0..10..-5}` ([#&#8203;17591](tailwindlabs/tailwindcss#17591)) - Work around a Chrome rendering bug when using the `skew-*` utilities ([#&#8203;17627](tailwindlabs/tailwindcss#17627)) - Ensure container quer...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants