Skip to content

Commit dd1ca3c

Browse files
Do not wrap color-mix in a @supports rule if one already exists (#19450)
Related issue: #19445 ## Summary Fixes an issue where tailwindcss wraps `color-mix` inside a `@supports` block even if the original code already checks for support. Uncompiled Code: ```css @Utility foo { @supports (color: color-mix(in lab, red, red)) { background: color-mix(in lab, var(--color-1), var(--color-2)); } } ``` ### Compiled code: Current behavior https://play.tailwindcss.com/KSvR7wefdh?file=css ```css @layer utilities { .foo { @supports (color: color-mix(in lab, red, red)) { background: var(--color-1); @supports (color: color-mix(in lab, red, red)) { background: color-mix(in lab, var(--color-1), var(--color-2)); } } } ``` ### Compiled code: Fixed behavior ```css @layer utilities { @supports (color: color-mix(in lab, red, red)) { .foo { background: color-mix(in lab, var(--color-1), var(--color-2)); } } ``` ## Test plan I have tested this by writing a new test that was at first failing. Now it passes. --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me>
1 parent 73b5df6 commit dd1ca3c

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Do not wrap `color-mix` in a `@supports` rule if one already exists ([#19450](https://github.com/tailwindlabs/tailwindcss/pull/19450))
13+
1014
### Added
1115

1216
- _Experimental_: Add `@container-size` utility ([#18901](https://github.com/tailwindlabs/tailwindcss/pull/18901))

packages/tailwindcss/src/ast.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ export function optimizeAst(
285285
if (
286286
polyfills & Polyfills.ColorMix &&
287287
node.value.includes('color-mix(') &&
288+
!context.supportsColorMix &&
288289
!context.keyframes
289290
) {
290291
colorMixDeclarations.get(parent).add(node)
@@ -382,6 +383,8 @@ export function optimizeAst(
382383
else if (node.kind === 'at-rule') {
383384
if (node.name === '@keyframes') {
384385
context = { ...context, keyframes: true }
386+
} else if (node.name === '@supports' && node.params.includes('color-mix(')) {
387+
context = { ...context, supportsColorMix: true }
385388
}
386389

387390
let copy = { ...node, nodes: [] }

packages/tailwindcss/src/index.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5812,6 +5812,28 @@ describe('`color-mix(…)` polyfill', () => {
58125812
}"
58135813
`)
58145814
})
5815+
5816+
it('does not apply optimizations when already inside a @supports (color: color-mix... block', async () => {
5817+
await expect(
5818+
compileCss(
5819+
css`
5820+
@tailwind utilities;
5821+
@utility mixed {
5822+
@supports (color: color-mix(in lab, red, red)) {
5823+
background: color-mix(in oklab, var(--color-1), var(--color-2) 0%);
5824+
}
5825+
}
5826+
`,
5827+
['mixed'],
5828+
),
5829+
).resolves.toMatchInlineSnapshot(`
5830+
"@supports (color: color-mix(in lab, red, red)) {
5831+
.mixed {
5832+
background: color-mix(in oklab, var(--color-1), var(--color-2) 0%);
5833+
}
5834+
}"
5835+
`)
5836+
})
58155837
})
58165838

58175839
describe('`@property` polyfill', async () => {

0 commit comments

Comments
 (0)