Skip to content

Extract keyframe name when followed by comma #17352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix class extraction followed by `(` in Pug ([#17320](https://github.com/tailwindlabs/tailwindcss/pull/17320))
- Ensure `@keyframes` for theme animations are emitted if they are referenced following a comma
- Vite: Ensure that updates to an imported CSS file are properly propagated after updating templates ([#17347](https://github.com/tailwindlabs/tailwindcss/pull/17347))
- Pre process `Slim` templates embedded in Ruby files ([#17336](https://github.com/tailwindlabs/tailwindcss/pull/17336))
- Error when input and output files resolve to the same file when using the CLI ([#17311](https://github.com/tailwindlabs/tailwindcss/pull/17311))
Expand Down
12 changes: 8 additions & 4 deletions packages/tailwindcss/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ export function optimizeAst(ast: AstNode[], designSystem: DesignSystem) {

// Track used animation names
if (node.property === 'animation') {
let parts = node.value.split(/\s+/)
for (let part of parts) usedKeyframeNames.add(part)
for (let keyframeName of extractKeyframeNames(node.value))
usedKeyframeNames.add(keyframeName)
}

parent.push(node)
Expand Down Expand Up @@ -438,8 +438,8 @@ export function optimizeAst(ast: AstNode[], designSystem: DesignSystem) {
)
if (variableUsed) {
if (declaration.property.startsWith(designSystem.theme.prefixKey('--animate-'))) {
let parts = declaration.value!.split(/\s+/)
for (let part of parts) usedKeyframeNames.add(part)
for (let keyframeName of extractKeyframeNames(declaration.value!))
usedKeyframeNames.add(keyframeName)
}

continue
Expand Down Expand Up @@ -605,3 +605,7 @@ function isVariableUsed(

return false
}

function extractKeyframeNames(value: string): string[] {
return value.split(/[\s,]+/)
}
43 changes: 43 additions & 0 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,49 @@ describe('Parsing theme values from CSS', () => {
`)
})

// https://github.com/tailwindlabs/tailwindcss/issues/17332
test('extracts keyframe names followed by comma', async () => {
expect(
await compileCss(
css`
@theme {
--animate-test: 500ms both fade-in, 1000ms linear 500ms spin infinite;

@keyframes fade-in {
from {
opacity: 0%;
}
to {
opacity: 100%;
}
}
}

@tailwind utilities;
`,
['animate-test'],
),
).toMatchInlineSnapshot(`
":root, :host {
--animate-test: .5s both fade-in, 1s linear .5s spin infinite;
}

.animate-test {
animation: var(--animate-test);
}

@keyframes fade-in {
from {
opacity: 0;
}

to {
opacity: 1;
}
}"
`)
})

test('keyframes outside of `@theme are always preserved', async () => {
expect(
await compileCss(
Expand Down