Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 84404ce

Browse files
committed
Don’t generate duplicate rule implementations
If multiple candidates resolved to the same rule the properties would get added more than once to the same rule. For instance: class:text-blue-500 class1:text-blue-500 class2:text-blue-500 results in .text-blue-500 having the properties set 3 times.
1 parent b2e0840 commit 84404ce

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/lib/generateRules.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ function inKeyframes(rule) {
267267

268268
function generateRules(candidates, context) {
269269
let allRules = []
270+
let allSelectors = new Set()
270271

271272
for (let candidate of candidates) {
272273
if (context.notClassCache.has(candidate)) {
@@ -285,8 +286,19 @@ function generateRules(candidates, context) {
285286
continue
286287
}
287288

289+
matches = matches.filter(([_, rule]) => {
290+
return !rule.selector
291+
|| !allSelectors.has(rule.selector)
292+
})
293+
288294
context.classCache.set(candidate, matches)
289295
allRules.push(...matches)
296+
297+
matches.forEach(([_, rule]) => {
298+
if (rule.selector) {
299+
allSelectors.add(rule.selector)
300+
}
301+
})
290302
}
291303

292304
return allRules.map(([{ sort, layer, options }, rule]) => {

tests/variants.test.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,7 @@
6767

6868
<!-- Things that look like variants but are not -->
6969
<h1 class:text-blue-500={shouldBeBlue}></h1>
70+
<h1 class1:text-blue-500={shouldBeBlue}></h1>
71+
<h1 class2:text-blue-500={shouldBeBlue}></h1>
7072
</body>
7173
</html>

0 commit comments

Comments
 (0)