FULL AI ANALYSIS

Next.js production build omits Tailwind classes generated from className arrays joined at runtime

Generated Oct 20, 2026, 9:41:02 AM

Analysis summary

Tailwind's purge/scanner finds only literal class name strings at build time. When you build class names dynamically (array.join, string concatenation of computed values, or runtime mapping), the scanner cannot infer the set of utilities to include, so they are removed from the final CSS. Safelisting works but can balloon file size. Better patterns are to keep the set of possible class names statically analyzable (mapping objects, conditional expressions with explicit strings) or generate a limited safelist with regex that matches the valid variants. Alternatives include using twin.macro, cx helpers, or using the new JIT with explicit safelist generation.

Possible causes

Tailwind purge cannot detect class names built dynamically via array.join at compile time

95%

tailwind.config.content paths missing some component files at build time

40%

Production minifier or postcss removing unused classes incorrectly configured

20%

Using an older Tailwind/JIT version with a bug in scanning dynamic patterns

15%

Suggested fixes

1

Diagnostic step 1

Replace runtime array.join with a mapping helper that returns known class strings. Example: const sizeMap = { small: 'text-sm', large: 'text-lg' }; className={`${sizeMap[size]} ${colorMap[color]}`};

2

Diagnostic step 2

If mapping isn't possible, create a concise safelist with a regex that only matches the finite set you actually use, e.g., safelist: [/^text-(sm|md|lg|xl)$/, /^text-(red|blue|green)-500$/].

3

Diagnostic step 3

Run tailwindcss --content <paths> --output debug.css in a dev environment to confirm which classes are emitted.

4

Diagnostic step 4

Avoid arbitrary string concatenation for classes; prefer explicit strings or library helpers that keep variants static.

5

Diagnostic step 5

If using third-party components, ensure their files are included in tailwind.config.js content globs.