Skip to content

Commit 99a5b8e

Browse files
committed
fix empty canonicalization
When we canonicalized a set of classes into a new class, then we marked the existing classes as "droppable", meaning they should be removed in favor of the replacement. However, if the replacement is part of the existing class list, it means that we would get rid of everything since the replacement is now marked for removal. Example: ``` w-[calc(1rem+0.25rem)] h-[calc(1rem+0.25rem)] size-5 ``` The w-* and h-* would be collapsed into `w-5 h-5`. Then the result of this would look like: ``` w-5 h-5 size-5 ``` Now the `w-5 h-5` will be collapsed into `size-5`, and `size-5` itself also can be replaced by itself. But this means that `size-5` is marked for removal and the entire class list becomes empty. This fixes that.
1 parent e098a92 commit 99a5b8e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/tailwindcss/src/canonicalize-candidates.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,17 @@ function collapseCandidates(options: InternalCanonicalizeOptions, candidates: st
446446
designSystem.storage[UTILITY_SIGNATURE_KEY].get(signatureOptions).get(replacement)
447447
if (signature !== collapsedSignature) continue // Not a safe replacement
448448

449-
// We can replace all items in the combo with the replacement
449+
// Use the replacement
450+
result.add(replacement)
451+
452+
// We can replace all items in the combo with the replacement. If the
453+
// replacement is already part of the combo, keep that one around.
450454
for (let item of combo) {
451-
drop.add(candidates[item])
455+
if (candidates[item] !== replacement) {
456+
drop.add(candidates[item])
457+
}
452458
}
453459

454-
// Use the replacement
455-
result.add(replacement)
456460
break
457461
}
458462
}

0 commit comments

Comments
 (0)