Preview styled, live bare? Tailwind purge
In the builder preview the dashboard looks finished: coloured badges, padded cards, the right spacing. You deploy. On the live URL half the layout is gone. Text sits on a white page. Buttons look like plain links. The markup is still there in DevTools, but many of the class names that drove the look are missing from the CSS file the browser downloaded. Sites built with Lovable, Bolt, Replit, v0 or Cursor hit this often: those stacks lean on Tailwind, and the production build keeps only class names it can see as full strings in source.
The symptom
- Preview (or
npm run dev) looks correct; the production URL looks sparse or broken. - DevTools Elements still shows classes like
bg-emerald-500ormd:grid-cols-3on nodes, but the Styles panel has no matching rules. - A hard refresh and an Incognito window do not fix it.
- Only some sections fail: static marketing blocks look fine; status chips, theme toggles or list rows built from data look wrong.
- The Network tab shows a small hashed CSS file from the production build, not the large stylesheet from local development.
The cause
Tailwind scans your source for complete class strings, then writes only those utilities into the production CSS. In development the engine is more forgiving and often generates classes on the fly. In production it does not. Anything the scanner cannot see as a full literal is dropped.
- String templates. Code like
bg-${color}-500or`p-${size}`never appears as a finished class name, so the build omits it. - Runtime maps. Objects such as
{ ok: 'text-green-600', bad: 'text-red-600' }are safe only when every value is a full string literal. Building the string later is not. - Classes from the database or CMS. If an editor stores
bg-indigo-600in a row and your code puts that string on a node, the scanner never saw it at build time. - Wrong content paths. Tailwind only scans the globs in its config. A UI file missing from
contentwill not contribute classes. - Safelist gaps. Dynamic sets need an explicit safelist (or a static map of full class names). Without one, production CSS silently shrinks.
Preview hosts and local dev often hide the bug. The live build is the first place the missing utilities become obvious.
Step-by-step diagnosis
- Compare preview and live on the same route. Note which blocks lose colour, spacing or grid behaviour.
- Inspect one broken node. If the class is present in HTML but absent from Styles, the CSS file never included it.
- Open the production CSS from the Network tab and search for one missing utility (for example
bg-emerald-500). A missing hit means the build dropped it. - Search your source for template patterns:
${inside class strings, concatenation inclassName, or helpers that build names from props. - Check Tailwind content globs in
tailwind.config. Confirm every folder that renders UI is listed. - Reproduce with a production build locally (
npm run build && npm run preview). If it fails there too, the host is not the root cause.
Fixes per builder or host
Lovable and Bolt
Prefer a static map of full class names for status, size and colour variants instead of building strings. Example: look up statusStyles[status] where every value is a complete literal. After a visual theme change, redeploy and re-check the live URL, not only the builder canvas. If the project exposes Tailwind config, add a safelist for any truly dynamic set you cannot rewrite.
v0 and Cursor (Vite + React + Tailwind, or Next.js)
Replace dynamic class construction with complete literals or a clsx/cva variant map. Keep every utility written out in source. Extend the Tailwind content array if components live outside the default paths. For Next.js, run a production build before you trust a fix; the dev server will keep lying to you.
Replit
Confirm the deployment runs the production build command, not a lingering dev process. Re-check Tailwind content paths after you move files between folders. Test the deployment URL after each CSS-related change.
Any static host (Vercel, Netlify, Cloudflare Pages)
Purge is a build-time issue, not a CDN cache issue. Still hard-refresh once after deploy so you are not looking at an old CSS file. If you use a service worker, unregister it while debugging so a cached stylesheet cannot mask the new build.
How to verify
- A local production build matches the live URL.
- Searching the built CSS finds every utility you rely on for status chips, grids and spacing.
- A private window on the live URL matches the intended design for both static and data-driven sections.
- Changing a status in seed data still picks a styled variant whose full class string exists in source or safelist.
Prevention
- Treat full class literals as part of the contract. Do not assemble Tailwind names with templates.
- Keep a small static map for colours, sizes and states; add new entries as full strings.
- Review Tailwind
contentwhenever you add a UI folder or a shared package. - Add a production-build check to your release habit: if local
build && previewlooks wrong, do not ship.
