-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
[v4] "hidden" is not the last display utility anymore #15884
Comments
You shouldn't ever have two utilities that apply the same CSS property in the same context, because -as you have found - order is not guaranteed. Consider toggling between them. |
With any other CSS property I would agree with you, but with As I am already using v4 for my project, I have "solved" this problem with a zero-width-breakpoint-version of |
You could use the |
Interesting, thanks for the tip, that might be a good alternative. |
@iquito Were you able to make it work with the |
@philipp-spiess Yes, the It was quite a bit of work though even in my not-so-huge application, so changing the order of the |
My Now, first, this is a breaking change, and I honestly don't know where it might pop up where I haven't noticed it yet. Second, how do I do this now? Or even, how was I supposed to do it before? The I guess from now on it's |
@finkrer the problem only exists if you set the E.g.: https://play.tailwindcss.com/dvYE6VFc7T This kind of issue already existed in v3, especially because unfortunately class order in the HTML doesn't matter. <div class="text-red-500 text-blue-500">…</div>
<div class="text-blue-500 text-red-500">…</div> E.g.: https://play.tailwindcss.com/d2zsKyorBH If you use the VSCode Intellisense plugin then you should see some squiggles (as you can see in the Tailwind Play link). If you use the prettier plugin, then we sort the classes to be consistent and to reduce the amount of potential issues you run into. |
I feel @finkrer's issue too. I have a button component which has It's a common practice and pattern to be able to do that so easily and have It's a breaking change which, if it can be refactored, could be reverted easily (famous last words). Thanks for all your work 🙌 |
I know that we could use the Even if they upgrade to TW 4, now they have to choose from |
Is there any specific reasoning behind this decision? I mean, there are hundreds of millions of projects; do you expect everyone to now rebuild their code structure to match the new order? It seems to me that this is a big breaking change that wasn't properly addressed in the upgrade guide. |
I've encountered the same on one of my own projects. I was using it to facilitate manual switching between a Light/Dark mode (and hide/display the icon in the button). It's an easy enough change in my codebase to replace with |
Hi @philipp-spiess , thanks for clarifying the current situation on the issue. I wanted to add that the suggestion to use the HTML Example: On Tailwind 4, the On Tailwind 3, the hidden is ignored because of the flex class: It looks like this was a known thing on v3: #9979 Anyway, just wanted to share this and mention that I'm still unsure of what path I should take... it sounds like the recommended way is to really avoid having 2 classes that control the display at the same time, but that's going to be a big change here since we were making use of the tailwind Thanks again! |
Hey @philipp-spiess. Thanks for your response.
Please reconsider this change as it impacts the whole web ecosystem and it's not just a matter of toggling the class in a React component. Thanks! |
Can this linter standalone instead of in VSCode? Some of our engineers don't run VSCode, and it would be great to catch this before hitting production. Running this in CI or as part of our suite of linters would be great. |
Having two display classes on the same element overriding each other is perfectly fine in CSS. It's not optimal in the same context, so an IntelliSense warning makes sense, but I wouldn't introduce a breaking change like this because of it. In practice, it's more likely that // renders as `inline-block hidden`, without IntelliSense warning
<Component className={'hidden'} />
function Component({ className, ...rest }) {
return <div className={classNames('inline-block', className)} {...rest} />;
} So having @import 'tailwindcss';
/*
Note on breaking change in Tailwind CSS v4...
*/
.hidden {
display: none;
} |
I use Nextjs 15, and My work around was to add the exclamation to |
What version of Tailwind CSS are you using?
v4.0
Reproduction URL
https://play.tailwindcss.com/1XH8TJa6s3 for v4 (element is shown)
https://play.tailwindcss.com/Ajm578zcYz for v3.4.15 (element is not shown)
Describe your issue
The order of the
display
utilities has slightly changed in v4, puttinghidden
somewhere in the middle of these utilities by default (afterblock
, but beforeinline-block
orinline-flex
), where in v3.4 it was at the end of all thedisplay
utilities. I have used TailwindCSS often like this:Then I remove or re-add the hidden class with Javascript, which worked fine in v3. In v4 this does not work with
inline-block
anymore (becauseinline-block
comes afterhidden
in the generated CSS), while it does work withblock
(as it comes beforehidden
). I found the behavior better in v3.4, wherehidden
was assumed to be the preferred/overriding value (if set) of all the display utilities and comes last in the definitions. I could imagine many people usedhidden
in this way and will find the new order surprising.The text was updated successfully, but these errors were encountered: