Syntax Highlighting Colors Fix
The Problem
The syntax highlighting colors in code blocks keep disappearing from the domain sites (biturl, contacts, homepage, etc.). This happens because Tailwind CSS purges unused classes during build time.
Why This Keeps Happening
-
Dynamic Class Construction: The
CodeHighlight.tsxcomponent uses dynamic class names like:text-purple-400(keywords)text-yellow-400(strings)text-orange-400(numbers)- etc.
-
Tailwind's Static Analysis: Tailwind CSS v4 uses static analysis to determine which classes to include in the final CSS. It cannot detect dynamically constructed class names.
-
Purging: During production builds, Tailwind removes any classes it doesn't find in the source code, causing the colors to disappear.
The Permanent Solution
We've added a safelist to all domain site Tailwind configurations. This tells Tailwind to always include these classes regardless of whether it finds them in the code.
Updated Files (January 2025)
apps/webs/biturl/tailwind.config.tsapps/webs/homepage/tailwind.config.tsapps/webs/isup/tailwind.config.tsapps/webs/sell/tailwind.config.tsapps/webs/send/tailwind.config.tsapps/webs/sms/tailwind.config.tsapps/webs/talk/tailwind.config.tsapps/webs/telco/tailwind.config.tsapps/webs/transcribe/tailwind.config.tsapps/webs/voicemail/tailwind.config.tsapps/webs/voip/tailwind.config.ts
Added Configuration
safelist: [
// Syntax highlighting colors for code blocks
"text-purple-400", // keywords
"text-yellow-400", // strings
"text-orange-400", // numbers
"text-blue-400", // functions
"text-green-400", // classes
"text-gray-300", // default
"text-gray-400", // properties
"text-gray-500", // comments
],How to Apply the Fix
-
Development: Restart the dev server after making changes to tailwind.config.ts
# Kill the existing process pkill -f "next dev" # Start again pnpm dev -
Production: The changes will be applied automatically on the next build
Alternative Solutions (Not Recommended)
- Inline Styles: Use inline styles instead of Tailwind classes in CodeHighlight.tsx
- Static Classes: Use a map of static class names instead of dynamic construction
- CSS Modules: Use traditional CSS instead of Tailwind for syntax highlighting
Why We Use Safelist
The safelist approach is the best because:
- It maintains the clean Tailwind-based approach
- It's explicit about which classes we need
- It doesn't require changing the component code
- It's the official Tailwind recommendation for this scenario
Monitoring
If colors disappear again:
- Check if new color classes were added to CodeHighlight.tsx
- Add any new classes to the safelist
- Ensure the safelist is in all relevant tailwind.config.ts files
Script for Future Updates
Use the provided update-tailwind-safelist.js script to update all configs at once:
node update-tailwind-safelist.js