Skip to content

Commit 0e262a1

Browse files
authored
@apply is not allowed inside @keyframes (#14687)
This PR makes sure that you cannot use `@apply` inside `@keyframes`. While some utilities can be used in `@keyframes`, the moment you introduce a variant, that's not going to work anymore because they need to operate on selectors which `@keyframes` don't have. This PR now removes all usages of `@apply` in `@keyframes`.
1 parent 4395aac commit 0e262a1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/tailwindcss/src/apply.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
import { walk, type AstNode } from './ast'
1+
import { walk, WalkAction, type AstNode } from './ast'
22
import { compileCandidates } from './compile'
33
import type { DesignSystem } from './design-system'
44
import { escape } from './utils/escape'
55

66
export function substituteAtApply(ast: AstNode[], designSystem: DesignSystem) {
77
walk(ast, (node, { replaceWith }) => {
88
if (node.kind !== 'rule') return
9+
10+
// Do not allow `@apply` rules inside `@keyframes` rules.
11+
if (node.selector[0] === '@' && node.selector.startsWith('@keyframes')) {
12+
walk(node.nodes, (child) => {
13+
if (
14+
child.kind === 'rule' &&
15+
child.selector[0] === '@' &&
16+
child.selector.startsWith('@apply ')
17+
) {
18+
throw new Error(`You cannot use \`@apply\` inside \`@keyframes\`.`)
19+
}
20+
})
21+
return WalkAction.Skip
22+
}
23+
924
if (!(node.selector[0] === '@' && node.selector.startsWith('@apply '))) return
1025

1126
let candidates = node.selector

packages/tailwindcss/src/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ describe('arbitrary properties', () => {
148148
})
149149

150150
describe('@apply', () => {
151+
it('@apply in @keyframes is not allowed', () => {
152+
return expect(() =>
153+
compileCss(css`
154+
@keyframes foo {
155+
0% {
156+
@apply bg-red-500;
157+
}
158+
}
159+
`),
160+
).rejects.toThrowErrorMatchingInlineSnapshot(
161+
`[Error: You cannot use \`@apply\` inside \`@keyframes\`.]`,
162+
)
163+
})
164+
151165
it('should replace @apply with the correct result', async () => {
152166
expect(
153167
await compileCss(css`

0 commit comments

Comments
 (0)