diff --git a/packages/tailwindcss/src/variants.ts b/packages/tailwindcss/src/variants.ts index 82a2b8592..24b72ce42 100644 --- a/packages/tailwindcss/src/variants.ts +++ b/packages/tailwindcss/src/variants.ts @@ -447,6 +447,7 @@ export function createVariants(theme: Theme): Variants { if (variant.modifier) return null let didApply = false + let replacement: AstNode | null = null walk([ruleNode], (node, ctx) => { if (node.kind !== 'rule' && node.kind !== 'at-rule') return WalkAction.Continue @@ -492,7 +493,7 @@ export function createVariants(theme: Theme): Variants { rules.push(negatedAtRule) } - Object.assign(ruleNode, styleRule('&', rules)) + replacement = styleRule('&', rules) // Track that the variant was actually applied didApply = true @@ -500,6 +501,10 @@ export function createVariants(theme: Theme): Variants { return WalkAction.Skip }) + if (replacement) { + Object.assign(ruleNode, replacement) + } + // TODO: Tweak group, peer, has to ignore intermediate `&` selectors (maybe?) if (ruleNode.kind === 'rule' && ruleNode.selector === '&' && ruleNode.nodes.length === 1) { Object.assign(ruleNode, ruleNode.nodes[0])