GitHub Migrates to CSS Modules, Cutting Server-Side Render Time by 55%
Key point
The full migration removed styled-components and reduced server-side rendering time by 55%.
Details
GitHub replaced its CSS-in-JS implementation with CSS Modules to resolve performance bottlenecks caused by a surge in component counts. The shift eliminated client-side style initialization and server-side collection costs, resulting in a 55% reduction in server-side render time and 25% faster component initialization.
Incremental Migration Strategy
The Primer Design System team adopted a cautious, phased approach to avoid breaking the GitHub UI. Each component was updated using a specific workflow:
- Translation: Existing styles were converted to CSS Modules files.
- Feature Flags: Toggles allowed switching between old and new styles for controlled rollout.
- Visual Regression: Tests verified identical snapshots between the old and new implementations.
- Staged Rollout: Changes were released to internal teams, then GitHub staff, and finally all users.
By December 2024, all Primer components had migrated to CSS Modules, delivering immediate performance wins.
Removing the sx Prop
A major hurdle was the sx prop, a styling standard at GitHub that offered excellent TypeScript support but incurred high runtime costs. To remove styled-components entirely, the team had to eliminate thousands of sx usages.
- Wrapper Library: A temporary package,
@primer/styled-react, allowed legacysxusage while new components used CSS Modules. - Automated Migration: In April 2025, a rotation of 8 engineers migrated 6,419
sxprops over six months using custom VS Code plugins and codemods, yielding 1–22% SSR improvements on specific pages. - AI Assistance: By April 2026, the remaining 895
sxprops were cleared in three weeks by two engineers using Copilot coding agents.
Finalizing Theming and Cleanup
The final phase involved decoupling GitHub’s seven themes (including high-contrast variations) from styled-components. After two months of migration and feature-flagged testing, GitHub achieved 100% CSS Modules adoption in June 2026. This re-platforming removed styled-components and styled-system from the codebase, enhancing performance and user experience without service interruptions.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.