FULL AI ANALYSIS

Tailwind classes generated from runtime template literals missing in production build (Next.js / React)

Generated Oct 21, 2026, 9:46:27 AM

Analysis summary

Tailwind's purge (content scanner) runs at build time and cannot detect class names built by runtime expressions or concatenated template literals. The typical remedies are: provide explicit safelist patterns that match dynamic possibilities, generate classes using a known finite map (object lookup) so the build-time parser sees the keys, or use the @apply directive in component CSS. Minification/build transforms that inline or mangle template strings can also hide patterns from the scanner; using string literals or explicit mappings is robust.

Possible causes

Tailwind purgeer cannot detect classes created from runtime concatenation/template literals and removes them from production CSS

95%

Safelist configured but pattern too narrow or incorrectly formatted for production scanner

53%

A build-time minifier or transpiler rewrote template literals making scanner miss classes

37%

Using third-party components that dynamically add classes after Tailwind has purged CSS

22%

Suggested fixes

1

Diagnostic step 1

Replace runtime concatenation with a mapping: create an object map like const bg = { primary: 'bg-blue-500', ... } and reference map[variant] so build-time analysis sees literal strings.

2

Diagnostic step 2

If mapping is impractical, add a safelist array in tailwind.config.js with regex patterns that cover the dynamic variants (e.g., safelist: [{ pattern: /bg-(red|blue|green)-500/ }]).

3

Diagnostic step 3

Avoid relying on ephemeral DOM-only injections; where possible use @apply in a component CSS file to define reusable classes that Tailwind compiles.

4

Diagnostic step 4

Rebuild production and inspect the generated CSS bundle to confirm the expected class selectors are present; test by deploying to a staging environment before rolling to production.