Safelist in V4 #15291
-
It seems that V4 is not recognizing the colors implemented in the backend (if you are not using the full class name like text-{{ $color }}) . In version 3, I used to safelist them as shown below. How should I handle this in V4? tailwind.config.js in v3: |
Beta Was this translation helpful? Give feedback.
Replies: 20 comments 40 replies
-
You could consider using the <div style="color: var(--color-{{ $color }})"> Or <div style="color: var(--color-{{ $color }}-500)"> Etc |
Beta Was this translation helpful? Give feedback.
-
I believe regex patterns and/or variants don't work in v4. In v4 I have to list all 12 statically, e.g. The following pattern works in v3 but not in v4:
|
Beta Was this translation helpful? Give feedback.
-
Is there any news on how safelist will work in v4? (not using tailwind.config.js) |
Beta Was this translation helpful? Give feedback.
-
This is completely broken. Of these, only one colour displays on the page when using them dynamically.
|
Beta Was this translation helpful? Give feedback.
-
Am also facing the same issue. Have been relying on classes like |
Beta Was this translation helpful? Give feedback.
-
I don't have a lot of generated colors so ended up creating a <div class="text-green-600"></div>
<div class="text-yellow-600"></div>
<div class="text-red-600"></div> This get's picked up by the Tailwind compiler and works. |
Beta Was this translation helpful? Give feedback.
-
An solution is to enable support of safelist inside app.css , so we move away from JS config and have same behavior as before. Because is just very boring to hardcode those classes in somewhere. |
Beta Was this translation helpful? Give feedback.
-
The whole v4 update is a fascinating rollercoaster of emotions. Half of the things from v3 are missing and I am baffled how could this even be released in this state. Back to v3 boys and girls. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to implement something using this as part of the solution? At the moment it seems to only forces the color variables and nothing else. https://tailwindcss.com/docs/theme
|
Beta Was this translation helpful? Give feedback.
-
The removal of safelist is also a big issue for me, we have an in-house WYSIWYG editor based on TipTap and now I have to list all possible classes that the editor could set |
Beta Was this translation helpful? Give feedback.
-
Same here, no safelist support is a bummer ... |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Any update on how to best safelist in v4? |
Beta Was this translation helpful? Give feedback.
-
This is a complete slop solution.. but just paste your config with your safe list into any decent LLM .. ask it to generate all classnames in a single string separated by spaces. copy paste the classes onto a hidden div somewhere in your app. C’est complètement la merde - but it works. whatever. |
Beta Was this translation helpful? Give feedback.
-
That’s great news. I can throw out my slop generated class list.
…On Sun 6 Apr 2025 at 14:28, Falko Joseph ***@***.***> wrote:
neat, taking a look!
—
Reply to this email directly, view it on GitHub
<#15291 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDHLJONTG4WVLFVDL2WBCL2YEMYBAVCNFSM6AAAAABS6ZFEW2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENZUGA3TCMY>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Would be great to have some additional documentation on how to whitelist multiple classes, not just states. For example, this code is from a production codebase currently using v3:
The v4 docs don't appear to have a list of all the built-in number classes for padding, margin, height, etc. The documentation for This might seem like an edge case, but being able to safelist these kinds of classes is a pretty fundamental need when working with page builders like Storyblok. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
@source inline("{hover:,}bg-red-{50,{100..900..100},950}"); |
Beta Was this translation helpful? Give feedback.
-
this doesn't seem to work if you have prefix set. It won't generate media queries only the @import "tailwindcss" prefix(tw);
@source inline("{md:,lg:,xl:,}tw:grid-cols-{1..12}"); |
Beta Was this translation helpful? Give feedback.
-
~/code/projects/amnesia_admin/ cat src/index.css
@import '@fontsource-variable/open-sans' layer(vendor);
@import '@fontsource-variable/caveat' layer(vendor);
@import '@fontsource/kalam' layer(vendor);
@import '@fontsource/roboto' layer(vendor);
@import '@fontsource/pacifico' layer(vendor);
@import '@fontsource/lobster-two' layer(vendor);
/* See https://github.com/tailwindlabs/tailwindcss/discussions/15870 */
@import '@fortawesome/fontawesome-svg-core/styles.css' layer(vendor);
@import "tailwindcss";
@theme {
--font-kalam: "Kalam", "cursive";
--font-pacifico: "Pacifico", "cursive";
--font-lobster-two: "Lobster Two", "cursive";
--font-opensans: "Open Sans Variable", "sans-serif";
--font-caveat: "Caveat Variable", "cursive";
--font-roboto: "Roboto", "sans-serif";
}
@plugin "@tailwindcss/forms";
@source "../tailwind-safelist.txt";
/* Fonts */
@source inline('font-{sans,serif,mono,kalam,lobster-two,pacifico,opensans,caveat,roboto}');
/* Colors */
@source inline('{hover:,sm:,md:,lg:,xl:,2xl:}{border,fill,outline,ring,caret,bg,text}-{white,black,transparent,current,inherit}')
@source inline('{hover:,sm:,md:,lg:,xl:,2xl:}{border,fill,outline,ring,caret,bg,text}-{slate,gray,zinc,neutral,stone,red,orange,amber,yellow,lime,green,emerald,teal,cyan,sky,blue,indigo,violet,purple,fuchsia,pink,rose}-{50,{100..900..100},950}')
/* Margins and paddings */
@source inline('{hover:,sm:,md:,lg:,xl:,2xl:}{m,p}{x,y,t,b,l,r}-{auto,0,0.5,1,1.5,2,2.5,3,3.5,4,5,6,7,8,9,10,11,12,14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96}') It quickly fails with: So for now I'll keep using my Python script and |
Beta Was this translation helpful? Give feedback.
You could consider using the
style
attribute like:Or
Etc