Skip to content
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

Emit @keyframes in prefixed setup #16850

Merged
merged 1 commit into from
Feb 27, 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 @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Ensure `not-*` does not remove `:is(…)` from variants ([#16825](https://github.com/tailwindlabs/tailwindcss/pull/16825))
- Ensure `@keyframes` are correctly emitted when using a prefixed setup ([#16850](https://github.com/tailwindlabs/tailwindcss/pull/16850))

## [4.0.9] - 2025-02-25

Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export function optimizeAst(ast: AstNode[], designSystem: DesignSystem) {
variableDependencies,
)
if (variableUsed) {
if (declaration.property.startsWith('--animate-')) {
if (declaration.property.startsWith(designSystem.theme.prefixKey('--animate-'))) {
let parts = declaration.value!.split(/\s+/)
for (let part of parts) usedKeyframeNames.add(part)
}
Expand Down
67 changes: 67 additions & 0 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,73 @@ describe('Parsing theme values from CSS', () => {
`)
})

test('keyframes are generated when used in an animation within a prefixed setup', async () => {
expect(
await compileCss(
css`
@theme prefix(tw) {
--animate-foo: used 1s infinite;
--animate-bar: unused 1s infinite;

@keyframes used {
to {
opacity: 1;
}
}

@keyframes unused {
to {
opacity: 0;
}
}
}

@tailwind utilities;
`,
['tw:animate-foo'],
),
).toMatchInlineSnapshot(`
":root, :host {
--tw-animate-foo: used 1s infinite;
}

.tw\\:animate-foo {
animation: var(--tw-animate-foo);
}

@keyframes used {
to {
opacity: 1;
}
}"
`)
})

test('custom properties are generated when used from a CSS var with a prefixed setup', async () => {
expect(
await compileCss(
css`
@theme prefix(tw) {
--color-tomato: #e10c04;
}
@tailwind utilities;
.red {
color: var(--tw-color-tomato);
}
`,
[],
),
).toMatchInlineSnapshot(`
":root, :host {
--tw-color-tomato: #e10c04;
}

.red {
color: var(--tw-color-tomato);
}"
`)
})

// https://github.com/tailwindlabs/tailwindcss/issues/16374
test('custom properties in keyframes preserved', async () => {
expect(
Expand Down
6 changes: 3 additions & 3 deletions packages/tailwindcss/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ export class Theme {
if (!this.prefix) return this.values.entries()

return Array.from(this.values, (entry) => {
entry[0] = this.#prefixKey(entry[0])
entry[0] = this.prefixKey(entry[0])
return entry
})
}

#prefixKey(key: string) {
prefixKey(key: string) {
if (!this.prefix) return key
return `--${this.prefix}-${key.slice(2)}`
}
Expand Down Expand Up @@ -190,7 +190,7 @@ export class Theme {
fallback = value.value
}

return `var(${escape(this.#prefixKey(themeKey))}${fallback ? `, ${fallback}` : ''})`
return `var(${escape(this.prefixKey(themeKey))}${fallback ? `, ${fallback}` : ''})`
}

markUsedVariable(themeKey: string) {
Expand Down