Skip to content

Commit f8d7623

Browse files
adamwathanthecrypticacephilipp-spiess
authored
Preserve custom properties in keyframes (#16376)
Closes #16374 Ensure we don't remove custom properties from within `@keyframe` declarations. --------- Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com> Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: Philipp Spiess <hello@philippspiess.com>
1 parent 7bece4d commit f8d7623

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/tailwindcss/src/ast.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ export function optimizeAst(
286286

287287
// Track variables defined in `@theme`
288288
if (context.theme && node.property[0] === '-' && node.property[1] === '-') {
289-
cssThemeVariables.get(parent).add(node)
289+
if (!context.keyframes) {
290+
cssThemeVariables.get(parent).add(node)
291+
}
290292
}
291293

292294
// Track used CSS variables
@@ -354,6 +356,10 @@ export function optimizeAst(
354356

355357
// AtRule
356358
else if (node.kind === 'at-rule') {
359+
if (node.name === '@keyframes') {
360+
context = { ...context, keyframes: true }
361+
}
362+
357363
let copy = { ...node, nodes: [] }
358364
for (let child of node.nodes) {
359365
transform(child, copy.nodes, context, depth + 1)

packages/tailwindcss/src/index.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,44 @@ describe('Parsing theme values from CSS', () => {
16131613
`)
16141614
})
16151615

1616+
// https://github.com/tailwindlabs/tailwindcss/issues/16374
1617+
test('custom properties in keyframes preserved', async () => {
1618+
expect(
1619+
await compileCss(
1620+
css`
1621+
@theme {
1622+
--animate-foo: used 1s infinite;
1623+
1624+
@keyframes used {
1625+
to {
1626+
--other: var(--angle);
1627+
--angle: 360deg;
1628+
}
1629+
}
1630+
}
1631+
1632+
@tailwind utilities;
1633+
`,
1634+
['animate-foo'],
1635+
),
1636+
).toMatchInlineSnapshot(`
1637+
":root, :host {
1638+
--animate-foo: used 1s infinite;
1639+
}
1640+
1641+
.animate-foo {
1642+
animation: var(--animate-foo);
1643+
}
1644+
1645+
@keyframes used {
1646+
to {
1647+
--other: var(--angle);
1648+
--angle: 360deg;
1649+
}
1650+
}"
1651+
`)
1652+
})
1653+
16161654
test('keyframes are generated when used in an animation using `@theme inline`', async () => {
16171655
expect(
16181656
await compileCss(

0 commit comments

Comments
 (0)