Sebb
tailwind will go through your files and find classes using a RE.
So you can’t interpolate tailwind classes.
<div class={"w-#{@foo}"}> <!-- DOES NOT WORK -->
You have to
<div class={[
@foo==1 && "w-1",
@foo==2 && "w-2",
...
@foo==96 && "w-96"]}>
(or use @style)
How about a heex macro tailwind (and an accompanying attr type which gives all possible values)
attr :foo, :tailwind, range: [1, 2, 3, 4, 10, 24, 96]
...
<div class={[tailwind("w-#{@foo}"), "other classes ..."]}>
or maybe sth like this using a sigil
<div class={[~t"w-#{@foo}", "other classes ..."]}>
all tailwind macros could compile to an extra file (which is listed in tailwind.config to get parsed by the tailwind preprocessor)
# tailwind.lst
w-1, w-2, w-3, w-4, w-10, w-24, w-96
Trending in Discussions
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Aloha gang,
There’s a new class of AI model out from TypeSafe. Jev is their flagship model. You can learn about it here:
...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
D4no0
Oh my god, just banged my head for a few hours to understand that this is happening.
The thing is that this is not only not consistent, if you use same classes elsewhere, it will work (this also includes cached builds), but it also doesn’t show any kind of errors or warnings.
Actually as it currently stands, it seems that the limitation is that the string should be known at compile-time, things such as this work:
I have both the cases where a separate
.heexfile is used and whenrender/1from an.exfile is used, and both seem to be working when the strings are known at compile-time. Looking at this now, it seems that the configuration watches in.exfiles too:Have you found any solutions so somebody else would not stumble onto this bug?
tcoopman
Have a look at: Detecting classes in source files - Core concepts - Tailwind CSS
If you really need to have some classes, you can safelist them (see further on that page).
Basically, tailwind creates minimal css files by only including the class you’ve used. It can’t guess what classes you need.
zachdaniel
I think my
tailslibrary could be a good place to put this solution: Tails - Tailwind & Tailwind Component UtilitiesWe can make
classesinto a macro instead of a function, and support something like this:Then it would yell if you interpolate a variable in your classes but don’t provide a list of possible values. Then it would write the file that you’ve mentioned.
D4no0
This is a great resource, but the reality is that the most likely case is the one I stumbled across, where you have to invest a lot of time to understand what is happening.
It would be great if the tailwind elixir library could somehow detect and warn the user that class string interpolation can impact directly tailwind classes when used in conjunction with phoenix.
sodapopcan
I think having it more prominently documented would go a long way. As it stands, as linked by @tcoopman, the Tailwind documentation mentions it three sections in and a good scroll-length down the page. For Phoenix users,
phx_newcould maybe add a comment about it toapp.cssand/ortailwind.configsince so many people run into this (I did too).Warning via a macro would probably be really tricky as interpolating non-tailwind classes is perfectly valid. It would be hard to reliably judge what is and isn’t a Tailwind class.
EDIT: I guess you could warn on interpolation so long as there is way to turn it off since this is one of those things that once you know, you know.
D4no0
I think this is totally doable, especially with the tools elixir has at disposal. Think of it the following way:
~dont_caresigil;I think this is very important, especially for beginners that have a lot of complexity without this small implementation detail that is extremely hard to trace down.
sodapopcan
I wasn’t saying that any of that was hard. What’s potentially hard is determining what is an isn’t a Tailwind class, especially since TW class names are highly configurable. But ya, so long as you could turn it off it should be fine. And obviously not fire if you’ve used
--no-tailwind.sodapopcan
Plus this is perfectly valid:
But yes, so long as there is a way to turn it off it would be good.
D4no0
Indeed, this is very similar to the example I posted above.
What I want to focus on is not the commodity on how to approach this, but how to avoid having this almost impossible to trace bug.
This is the first time in my 5 years of elixir development when I literally had no idea what was going on, because after checking out on another branch (that was most probably when the cache was invalidated) the project was no longer working as expected, without any warnings, traces or ways to reproduce what happened.
sodapopcan
Cool, I clearly misunderstood your intent.
I agree it’s a problem.