-
Problem SummaryUsing Tailwind CSS v4.1 and Classes like the following were missing entirely from the compiled CSS:
This caused layouts to break or appear unstyled in modals or other nested components that aren’t immediately visible. CauseTailwind v4 injects styles only for classes used in the current render tree. This means:
Temporary Fix (Seeder Component)I worked around this by adding a hidden seeder component in the App.tsx file: const TailwindClassSeeder = () => (
<div className="hidden">
{/* Force these classes to be included */}
<div className="mr-auto ml-auto border shadow space-y-1 space-y-2 space-y-3">
<div className="flex-row bg-amber-500 bg-amber-700 bg-yellow-500 bg-orange-500">
<div className="bg-amber-100 bg-amber-200 bg-amber-300 bg-amber-400 bg-amber-600 bg-amber-800 bg-amber-900"></div>
</div>
</div>
</div>
); Has someone a solution for this? Initially everything was working it was only later on I started to experience this. I didn't find anything that could cause it. I went back in commits and checked things that could effect it + I reinstalled everything completely and removed the cache and so on. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Consider providing a git repo that reproduces the issue and we can take a look for you. |
Beta Was this translation helpful? Give feedback.
The
@source
rule didn't work. I have uninstalled@tailwindcss/vite
and installed tailwind again, but now usingnpm install -D tailwindcss@3 postcss autoprefixer
. This seems to have fixed the problem.Another way was to safelist all the styles I use with
@source inline("")
in the index.css file, but this is too much to manager for my use case.