-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Not recognizing selector:not(.class-name)
unless class-name
exists in content
#7750
Comments
I wonder how much this is a bug though. It seems to be working for elements, but not for classes. @layer base {
:not(p) {
background-color: magenta;
}
} I'd argue that if the So even though in principle there's nothing wrong with using selectors like Am I missing something? |
That's a great point @mrinx Currently, if you are using classes that don't exist in the actual code base, then you have to safelist them. If they do exist, then everything will work as expected. If you have code like: @layer base {
div:not(.some-class) {}
} And we follow the same rules, then The reason it works for just this: @layer base {
div:not(p) {}
} ... is because it doesn't include any classes. Internally we call everything that has a class "on-demandable" and the others, well, are not and will always be generated. We could have a special case where we ignore everything inside a My initial gut says that this is not a bug and works as expected. But as @adamwathan's demo shows, this can lead to super annoying results because right now the div doesn't have a background color, but if you all of a sudden use I'll provide a PR to fix this, and then we can evaluate whether we want this behaviour or not. |
For my part, I'd like to add another vote for this being considered a bug. I actually found this issue because it's already been a problem in the project I'm working on. Here's my perspective (apologies for the redundancy with what's already been shared, just spelling it all out to make sure I understand the behavior correctly): Example Code: @layer base {
div:not(.fancy) {
background-color: #999999;
}
}
Edit: After re-reading the earlier comments and the docs, this seems like it's somewhat of a philosophical question so I'm just going to leave one more example/analogy to try and explain what I mean in case it's helpful. Let's pretend we're building a bridge, and the rules we make are perfectly enforced:
|
This should be fixed, and will be available in the next release. You can already try it by using the insiders build |
Discussed in #7747
Originally posted by rjschie March 4, 2022
I'm not sure that this is a bug per-se, so I wanted to bring it up in a discussion first. If you have a rule in a layer, or plugin, that includes a
:not(.class-name)
, it will not add it to the output ifclass-name
is not found in the content. Once you addclass-name
it will recognize it, add it, and continue keeping it throughout that build (but once you stop the watcher and re-start it will revert back).You can see an example here: https://play.tailwindcss.com/fSaAQLAJ2i
In that playground, you'll see that the div's background is not
magenta
as you might expect, but if you addclass-name
to the class attribute, and then remove it, it will turnmagenta
.Adding
safelist: ['class-name']
to the config will work around this issue, but is this unintuitive? Is it a bug?The text was updated successfully, but these errors were encountered: