Don't remove keyframe stops when using important utilities (#12639)

* Don't remove keyframe stops when using important utilities

* Fix test

* fix linting
This commit is contained in:
Jordan Pittman 2023-12-21 12:17:12 -05:00 • committed by GitHub
parent a091db5df4
commit b048a0db80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View file

@ -118,10 +118,20 @@ function applyImportant(matches, classCandidate) {
let result = []
function isInKeyframes(rule) {
return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'
}
for (let [meta, rule] of matches) {
let container = postcss.root({ nodes: [rule.clone()] })
container.walkRules((r) => {
// Declarations inside keyframes cannot be marked as important
// They will be ignored by the browser
if (isInKeyframes(r)) {
return
}
let ast = selectorParser().astSync(r.selector)
// Remove extraneous selectors that do not include the base candidate

View file

@ -147,3 +147,32 @@ test('the important modifier works on utilities using :where()', () => {
`)
})
})
test('the important modifier does not break keyframes', () => {
let config = {
content: [
{
raw: html` <div class="!animate-pulse"></div> `,
},
],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@keyframes pulse {
50% {
opacity: 0.5;
}
}
.\!animate-pulse {
animation: 2s cubic-bezier(0.4, 0, 0.6, 1) infinite pulse !important;
}
`)
})
})