Skip to content

Commit

Permalink
Don't remove keyframe stops when using important utilities (#12639)
Browse files Browse the repository at this point in the history
* Don't remove keyframe stops when using important utilities

* Fix test

* fix linting
  • Loading branch information
thecrypticace committed Dec 21, 2023
1 parent f33d6a5 commit 8890775
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,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
Expand Down
30 changes: 30 additions & 0 deletions tests/important-modifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,34 @@ crosscheck(() => {
`)
})
})

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;
}
`)
})
})
})

0 comments on commit 8890775

Please sign in to comment.