diff --git a/CHANGELOG.md b/CHANGELOG.md index 056881e81d5a..e58f1db75e54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Nothing yet! +### Fixed + +- Don’t prefix classes within reused arbitrary variants ([#8992](https://github.com/tailwindlabs/tailwindcss/pull/8992)) ## [3.1.7] - 2022-07-29 diff --git a/src/lib/generateRules.js b/src/lib/generateRules.js index b7843258108b..0f441fb18018 100644 --- a/src/lib/generateRules.js +++ b/src/lib/generateRules.js @@ -129,7 +129,6 @@ function applyVariant(variant, matches, context) { } let args - let isArbitraryVariant = false // Find partial arbitrary variants if (variant.endsWith(']') && !variant.startsWith('[')) { @@ -145,8 +144,6 @@ function applyVariant(variant, matches, context) { return [] } - isArbitraryVariant = true - let fn = parseVariant(selector) let sort = Array.from(context.variantOrder.values()).pop() << 1n @@ -303,7 +300,7 @@ function applyVariant(variant, matches, context) { ...meta, sort: variantSort | meta.sort, collectedFormats: (meta.collectedFormats ?? []).concat(collectedFormats), - isArbitraryVariant, + isArbitraryVariant: isArbitraryValue(variant), }, clone.nodes[0], ] diff --git a/tests/arbitrary-variants.test.js b/tests/arbitrary-variants.test.js index be9704e87b71..a145ee5b4731 100644 --- a/tests/arbitrary-variants.test.js +++ b/tests/arbitrary-variants.test.js @@ -566,3 +566,52 @@ test('classes in arbitrary variants should not be prefixed', () => { `) }) }) + +test('classes in the same arbitrary variant should not be prefixed', () => { + let config = { + prefix: 'tw-', + content: [ + { + raw: ` +
should not be red
+
+
should be red
+
+
+
should not be red
+
should be red
+
+ `, + }, + ], + corePlugins: { preflight: false }, + } + + let input = ` + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + .foo .\[\.foo_\&\]\:tw-bg-white { + --tw-bg-opacity: 1; + background-color: rgb(255 255 255 / var(--tw-bg-opacity)); + } + + .foo .\[\.foo_\&\]\:tw-text-red-400 { + --tw-text-opacity: 1; + color: rgb(248 113 113 / var(--tw-text-opacity)); + } + + .\[\&_\.foo\]\:tw-bg-white .foo { + --tw-bg-opacity: 1; + background-color: rgb(255 255 255 / var(--tw-bg-opacity)); + } + + .\[\&_\.foo\]\:tw-text-red-400 .foo { + --tw-text-opacity: 1; + color: rgb(248 113 113 / var(--tw-text-opacity)); + } + `) + }) +})