Skip to content

Commit b048a0d

Browse files
Don't remove keyframe stops when using important utilities (#12639)
* Don't remove keyframe stops when using important utilities * Fix test * fix linting
1 parent a091db5 commit b048a0d

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/lib/generateRules.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,20 @@ function applyImportant(matches, classCandidate) {
118118

119119
let result = []
120120

121+
function isInKeyframes(rule) {
122+
return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'
123+
}
124+
121125
for (let [meta, rule] of matches) {
122126
let container = postcss.root({ nodes: [rule.clone()] })
123127

124128
container.walkRules((r) => {
129+
// Declarations inside keyframes cannot be marked as important
130+
// They will be ignored by the browser
131+
if (isInKeyframes(r)) {
132+
return
133+
}
134+
125135
let ast = selectorParser().astSync(r.selector)
126136

127137
// Remove extraneous selectors that do not include the base candidate

tests/important-modifier.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,32 @@ test('the important modifier works on utilities using :where()', () => {
147147
`)
148148
})
149149
})
150+
151+
test('the important modifier does not break keyframes', () => {
152+
let config = {
153+
content: [
154+
{
155+
raw: html` <div class="!animate-pulse"></div> `,
156+
},
157+
],
158+
corePlugins: { preflight: false },
159+
}
160+
161+
let input = css`
162+
@tailwind utilities;
163+
`
164+
165+
return run(input, config).then((result) => {
166+
expect(result.css).toMatchFormattedCss(css`
167+
@keyframes pulse {
168+
50% {
169+
opacity: 0.5;
170+
}
171+
}
172+
173+
.\!animate-pulse {
174+
animation: 2s cubic-bezier(0.4, 0, 0.6, 1) infinite pulse !important;
175+
}
176+
`)
177+
})
178+
})

0 commit comments

Comments
 (0)