Skip to content

Commit

Permalink
Fix missing !important when using @apply (#4854)
Browse files Browse the repository at this point in the history
* Add failing test for #4823

* Fix important variant `@apply`

Co-authored-by: Brad Cornes <bradlc41@gmail.com>
  • Loading branch information
adamwathan and bradlc committed Aug 27, 2021
1 parent 96ef150 commit 476d445
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/jit/lib/generateRules.js
Expand Up @@ -106,9 +106,9 @@ function applyVariant(variant, matches, context) {
let variantFunctionTuples = context.variantMap.get(variant)
let result = []

for (let [{ sort, layer, options }, rule] of matches) {
if (options.respectVariants === false) {
result.push([{ sort, layer, options }, rule])
for (let [meta, rule] of matches) {
if (meta.options.respectVariants === false) {
result.push([meta, rule])
continue
}

Expand Down Expand Up @@ -144,7 +144,7 @@ function applyVariant(variant, matches, context) {
continue
}

let withOffset = [{ sort: variantSort | sort, layer, options }, clone.nodes[0]]
let withOffset = [{ ...meta, sort: variantSort | meta.sort }, clone.nodes[0]]
result.push(withOffset)
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/jit/apply.test.css
Expand Up @@ -323,6 +323,15 @@ h2 {
padding-left: 1rem;
padding-right: 1rem;
}

.important-modifier-variant {
padding-left: 1rem;
padding-right: 1rem;
}

.important-modifier-variant:hover {
border-radius: 0.375rem !important;
}
@keyframes spin {
to {
transform: rotate(360deg);
Expand Down
1 change: 1 addition & 0 deletions tests/jit/apply.test.html
Expand Up @@ -33,6 +33,7 @@
<div class="use-with-other-properties-base use-with-other-properties-component"></div>
<div class="add-sibling-properties"></div>
<div class="important-modifier"></div>
<div class="important-modifier-variant"></div>
<div class="a b"></div>
<div class="foo"></div>
<div class="bar"></div>
Expand Down
4 changes: 4 additions & 0 deletions tests/jit/apply.test.js
Expand Up @@ -122,6 +122,10 @@ test('@apply', () => {
.important-modifier {
@apply px-4 !rounded-md;
}
.important-modifier-variant {
@apply px-4 hover:!rounded-md;
}
}
@layer utilities {
Expand Down

0 comments on commit 476d445

Please sign in to comment.