Skip to content

Commit 8890775

Browse files
committedDec 21, 2023
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 f33d6a5 commit 8890775

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
 

‎src/lib/generateRules.js

+10
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,20 @@ function applyImportant(matches, classCandidate) {
119119

120120
let result = []
121121

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

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

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

‎tests/important-modifier.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,34 @@ crosscheck(() => {
150150
`)
151151
})
152152
})
153+
154+
test('the important modifier does not break keyframes', () => {
155+
let config = {
156+
content: [
157+
{
158+
raw: html` <div class="!animate-pulse"></div> `,
159+
},
160+
],
161+
corePlugins: { preflight: false },
162+
}
163+
164+
let input = css`
165+
@tailwind utilities;
166+
`
167+
168+
return run(input, config).then((result) => {
169+
expect(result.css).toMatchFormattedCss(css`
170+
@keyframes pulse {
171+
50% {
172+
opacity: 0.5;
173+
}
174+
}
175+
176+
.\!animate-pulse {
177+
animation: 2s cubic-bezier(0.4, 0, 0.6, 1) infinite pulse !important;
178+
}
179+
`)
180+
})
181+
})
153182
})
183+

0 commit comments

Comments
 (0)
Please sign in to comment.