Skip to content

Use local user css cache for apply #7524

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

Merged
merged 13 commits into from
Feb 25, 2022
Prev Previous commit
Next Next commit
Don’t build local cache unless @apply is used
  • Loading branch information
thecrypticace committed Feb 24, 2022
commit a24e7945b59a4bc5579dd05f5b659c7476c083b9
23 changes: 22 additions & 1 deletion src/lib/expandApplyAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,27 @@ function buildApplyCache(applyCandidates, context) {
return context.applyClassCache
}

/**
* @param {() => ApplyCache} buildCacheFn
* @returns {ApplyCache}
*/
function lazyCache(buildCacheFn) {
let cache

return {
get: (name) => {
cache = cache || buildCacheFn()

return cache.get(name)
},
has: (name) => {
cache = cache || buildCacheFn()

return cache.has(name)
},
}
}

/**
* @param {ApplyCache[]} caches
* @returns {ApplyCache}
Expand Down Expand Up @@ -398,7 +419,7 @@ function processApply(root, context, localCache) {

export default function expandApplyAtRules(context) {
return (root) => {
let localCache = buildLocalApplyCache(root, context)
let localCache = lazyCache(() => buildLocalApplyCache(root, context))

processApply(root, context, localCache)
}
Expand Down