Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/important-modifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
`)
})
})