Skip to content
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

Remove class prefix in arbitrary variant that is used multiple times #8992

Merged
merged 2 commits into from Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/lib/generateRules.js
Expand Up @@ -129,7 +129,6 @@ function applyVariant(variant, matches, context) {
}

let args
let isArbitraryVariant = false

// Find partial arbitrary variants
if (variant.endsWith(']') && !variant.startsWith('[')) {
Expand All @@ -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
Expand Down Expand Up @@ -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],
]
Expand Down
49 changes: 49 additions & 0 deletions tests/arbitrary-variants.test.js
Expand Up @@ -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: `
<div class="[.foo_&]:tw-text-red-400 [.foo_&]:tw-bg-white">should not be red</div>
<div class="foo">
<div class="[.foo_&]:tw-text-red-400 [.foo_&]:tw-bg-white">should be red</div>
</div>
<div class="[&_.foo]:tw-text-red-400 [&_.foo]:tw-bg-white">
<div>should not be red</div>
<div class="foo">should be red</div>
</div>
`,
},
],
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));
}
`)
})
})