-
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
Some Tailwind classes are not extracted from Pug templates in Vue when elements have attributes #17313
Comments
Hey! This will be fixed by #17320, have you experienced other Pug related issues? |
@RobinMalfait Thank you for another super quick fix!
Unfortunately, that's somewhat hard to say for sure, but I hope not. My process is basically just:
I realize that this is not a super tight feedback loop. For all of our sakes, I wish that there were some way to make the feedback loop tighter. I mostly work with Ruby, where, when I encounter a bug in a gem, then I can open the source code of that Ruby gem in my text editor with gem 'the_gem_name', gitub: 'the-organization/the-repo', branch: 'the-bugfix-pr-branch-name' in my app's Then, I can either say regarding the bugfix PR either "Yes, I can confirm that this fixes all of my issues" or "This fixes X, but it doesn't fix Y". Unfortunately, I don't think that there is a way to do something similar, where I could check your PR against my app (before the PR is merged and released) and verify that it has resolved all of the issues? If there is some way, then please let me know, and I could try to do it to verify that your latest PR resolves all of the Tailwind issues that my app is currently seeing. We already seem close to a solution, though. Here's the visual diff for my app's Percy screenshots after going from Tailwind 4.0.9 to 4.0.{11,12,13,14}:And here's the visual diff for my app's Percy screenshots after going from Tailwind 4.0.9 to 4.0.15:As you can see, we are getting much closer to success (no visual diffs), so I am optimistic that your latest PR will fix all of the remaining issues. Each of those screenshots demonstrates I think just a single Tailwind class that was not extracted. In both cases, the relevant Pug code does have an HTML attribute or Vue directive in parentheses. Here's the relevant code for the top screenshot diff: https://github.com/davidrunger/david_runger/blob/8ed638e000b095de3c0fd344770449c33730a4b0/app/javascript/home/components/HomeHero.vue#L6-L14 And here's the relevant code for the bottom screenshot diff: https://github.com/davidrunger/david_runger/blob/8ed638e000b095de3c0fd344770449c33730a4b0/app/javascript/groceries/components/Sidebar.vue#L39-L43 All this is to say that, as I mentioned before, I hope (and mostly suspect) that #17320 will fix all of the remaining Pug-Tailwind issues that I'm seeing, but, as I also say, unfortunately it's hard to be fully sure of that without being able to actually try out a new release. |
Alright cool, thanks for that information! It does look like it's just the classes followed by a ![]() ![]() So this should be fixed by #17320 and will be available in the next release. |
@RobinMalfait Great -- thank you very much for checking both of those larger Pug Vue templates and for sharing the screenshots showing that all Tailwind classes are successfully extracted. I look forward to hopefully getting back on the latest Tailwind with the 4.0.16 release. :) |
Wanted to answer some of your questions as well:
The big issue we run into is that these templating languages have a lot of special syntax around classes. Whenever you use a literal string like Internally classes are separated by "boundary" characters. That means that if you look at One issue you will run into with Pug is Another one is So we remove
|
@RobinMalfait I really appreciate you taking the time and effort to provide that very helpful additional context. Your writeup makes it clear that parsing templating languages for Tailwind is a tricky challenge. I am grateful that y'all do it, so that we can use these templating languages with Tailwind. :) I use Pug in Vue and also Haml for my Rails views. Your comment made me curious how Tailwind would be able to handle something like So, that class would have to be provided in a p.text-4xl.text-right(class="px-2.5") (which Tailwind will be able to parse more straightforwardly, as you mentioned). Similarly, there are some other Tailwind classes, such as Trying to write something in Pug like
Right. ✅
Yeah, I guessed that I could theoretically do that, but it seemed like probably a lot more hassle than I really felt like investing, and I wasn't very confident that I'd be able to get this working with any amount of effort. 😅
Very cool! I tried this, and I am happy to report that, using Thanks again for all of your work on these Pug/Haml/Slim issues (and on Tailwind in general)! |
What version of Tailwind CSS are you using?
v4.0.15 (the latest released version, at the time of writing)
What build tool (or framework if it abstracts the build tool) are you using?
Vite 6.2.2, Vue 3.5.13, Pug 3.0.3 (the latest released version of each, at the time of writing)
What version of Node.js are you using?
v22.14.0 (the latest LTS release, at the time of writing)
What browser are you using?
Firefox (though I don't think it's relevant)
What operating system are you using?
Linux (Debian / MX Linux) (though I don't think it's relevant)
Reproduction URL
I cannot provide a Tailwind Play URL, because this bug is particular to Pug templates, whereas Tailwind Play only supports plain HTML.
But here's a public GitHub repo with a minimal reproduction: https://github.com/davidrunger/tailwind-pug-attr-bug-demo
And here's that GitHub repo imported into CodeSandbox: https://codesandbox.io/p/github/davidrunger/tailwind-pug-attr-bug-demo/main?file=%2Fsrc%2FApp.vue%3A4%2C1
Describe your issue
CSS styles are sometimes not included for some Tailwind classes in Pug templates in my Vue project.
In the reproduction linked above, there is this Vue component:
Actual
When viewed in the browser, only the
text-sky-600
class has any visible effect (making the text blue). Thebg-neutral-900
class does not have any effect (when served either via the Vite hot-reloading dev server or when compiled and viewed via the Vite static production preview server).Expected
I expect that the
bg-neutral-900
class in the Pug Vue template would cause Tailwind to include CSS that gives that text a dark background, which is what happens if we go back totailwindcss
and@tailwindcss/vite
at v4.0.9 :Additional context:
I recently reported a similar bug for this environment (Vue templates using Pug) here: #17211. That was fixed by #17252, which was included in the Tailwind 4.0.15 release today. Although that issue was fixed, this different issue (where the presence of an HTML attribute seems to cause not all Tailwind classes to be extracted from the Pug Vue template) is present in 4.0.15.
Thank you for Tailwind and for taking a look at this bug!
The text was updated successfully, but these errors were encountered: