-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix consecutive builds with at apply producing different CSS (#6999)
* Partition at rules before building context * remove unnecessary logic * Update changelog Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
- Loading branch information
1 parent
3a13cfc
commit a891867
Showing
5 changed files
with
125 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function partitionRules(root) { | ||
if (!root.walkAtRules) return | ||
|
||
let applyParents = new Set() | ||
|
||
root.walkAtRules('apply', (rule) => { | ||
applyParents.add(rule.parent) | ||
}) | ||
|
||
if (applyParents.size === 0) { | ||
return | ||
} | ||
|
||
for (let rule of applyParents) { | ||
let nodeGroups = [] | ||
let lastGroup = [] | ||
|
||
for (let node of rule.nodes) { | ||
if (node.type === 'atrule' && node.name === 'apply') { | ||
if (lastGroup.length > 0) { | ||
nodeGroups.push(lastGroup) | ||
lastGroup = [] | ||
} | ||
nodeGroups.push([node]) | ||
} else { | ||
lastGroup.push(node) | ||
} | ||
} | ||
|
||
if (lastGroup.length > 0) { | ||
nodeGroups.push(lastGroup) | ||
} | ||
|
||
if (nodeGroups.length === 1) { | ||
continue | ||
} | ||
|
||
for (let group of [...nodeGroups].reverse()) { | ||
let clone = rule.clone({ nodes: [] }) | ||
clone.append(group) | ||
rule.after(clone) | ||
} | ||
|
||
rule.remove() | ||
} | ||
} | ||
|
||
export default function expandApplyAtRules() { | ||
return (root) => { | ||
partitionRules(root) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters