Skip to content

Commit

Permalink
cache clone rule
Browse files Browse the repository at this point in the history
Otherwise every time we read this value it will be re-cloned
  • Loading branch information
RobinMalfait authored and adamwathan committed Aug 18, 2020
1 parent 5260c71 commit e417da2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/flagged/applyComplexClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ const extractUtilityNames = useMemo(
selector => selector
)

const cloneRuleWithParent = useMemo(
rule => rule.clone({ parent: rule.parent }),
rule => rule
)

function buildUtilityMap(css) {
let index = 0
const utilityMap = {}
Expand All @@ -101,9 +106,7 @@ function buildUtilityMap(css) {
utilityName,
classPosition: i,
get rule() {
// TODO: #perf every time we "read" this value we will create a copy.
// Is this an issue?
return rule.clone({ parent: rule.parent })
return cloneRuleWithParent(rule)
},
})
index++
Expand Down

0 comments on commit e417da2

Please sign in to comment.