Skip to content

Commit 478e959

Browse files
Don’t emit color-mix fallback rules inside @keyframes (#19419)
Fixes #19417
1 parent 563a016 commit 478e959

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Validate candidates similarly to Oxide ([#19397](https://github.com/tailwindlabs/tailwindcss/pull/19397))
2424
- Canonicalization: combine `text-*` and `leading-*` classes ([#19396](https://github.com/tailwindlabs/tailwindcss/pull/19396))
2525
- Correctly handle duplicate CLI arguments ([#19416](https://github.com/tailwindlabs/tailwindcss/pull/19416))
26+
- Don’t emit color-mix fallback rules inside `@keyframes` ([#19419](https://github.com/tailwindlabs/tailwindcss/pull/19419))
2627

2728
### Added
2829

packages/tailwindcss/src/ast.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,36 @@ it('should not emit exact duplicate declarations in the same rule', () => {
290290
`)
291291
})
292292

293+
it('should not emit color-mix() fallbacks inside @keyframes', () => {
294+
let ast = CSS.parse(css`
295+
@keyframes my-animation {
296+
0% {
297+
color: color-mix(in oklab, var(--color-emerald-600) 0%, transparent);
298+
}
299+
100% {
300+
color: color-mix(in oklab, var(--color-emerald-600) 0%, transparent);
301+
}
302+
}
303+
`)
304+
305+
let theme = new Theme()
306+
theme.add('--color-emerald-600', 'oklch(59.6% 0.145 163.225)')
307+
308+
let design = buildDesignSystem(theme)
309+
310+
expect(toCss(optimizeAst(ast, design))).toMatchInlineSnapshot(`
311+
"@keyframes my-animation {
312+
0% {
313+
color: color-mix(in oklab, var(--color-emerald-600) 0%, transparent);
314+
}
315+
100% {
316+
color: color-mix(in oklab, var(--color-emerald-600) 0%, transparent);
317+
}
318+
}
319+
"
320+
`)
321+
})
322+
293323
it('should only visit children once when calling `replaceWith` with single element array', () => {
294324
let visited = new Set()
295325

packages/tailwindcss/src/ast.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,18 @@ export function optimizeAst(
275275

276276
// Track used animation names
277277
if (node.property === 'animation') {
278-
for (let keyframeName of extractKeyframeNames(node.value))
278+
for (let keyframeName of extractKeyframeNames(node.value)) {
279279
usedKeyframeNames.add(keyframeName)
280+
}
280281
}
281282

282283
// Create fallback values for usages of the `color-mix(…)` function that reference variables
283-
// found in the theme config.
284-
if (polyfills & Polyfills.ColorMix && node.value.includes('color-mix(')) {
284+
// found in the theme config.
285+
if (
286+
polyfills & Polyfills.ColorMix &&
287+
node.value.includes('color-mix(') &&
288+
!context.keyframes
289+
) {
285290
colorMixDeclarations.get(parent).add(node)
286291
}
287292

0 commit comments

Comments
 (0)