GitHub Ditches CSS-in-JS for CSS Modules, Reports 55% Faster SSR After Three-Year Migration

MMS Founder
MMS • Daniel Curtis
Article originally posted on InfoQ. Visit InfoQ
image

GitHub has published an in-depth account of a three-year effort to move github.com off CSS-in-JS and onto CSS Modules, reporting a 55% reduction in server-side rendering time and 25% faster component initialisation across its Primer-powered design system.

Written by Primer engineers Josh Black and Marie Lucca, the post explains how component counts on certain pages began to explode in 2023, exposing scaling problems with the existing styled-components setup. Initial page loads, server render times and style update costs all grew with component count. The team picked CSS Modules because it kept native CSS features and co-location while removing client and server runtime work, letting styles roll up into static stylesheets delivered with the HTML.

For every Primer component the team added a CSS Modules variant, gated it behind a feature flag, verified parity with visual regression tests, then rolled it out from the Primer team to GitHub staff and finally all users. By December 2024, Primer itself was fully on CSS Modules. The harder half was the roughly 7,760 sx prop usages scattered across github.com, the de facto styling standard for years. A transitional @primer/styled-react package let sx keep working against migrated components during the crossover.

A typical conversion looks like this:

// Before
import { Button } from '@primer/styled-react';
<Button sx={{ bg: 'accent.emphasis', px: 3 }}>Pay</Button>

// After
import { Button } from '@primer/react';
import styles from './PayButton.module.css';
<Button className={styles.pay}>Pay</Button>

A rotation of eight engineers migrated 6,419 props over six months, seeing SSR improvements ranging from 3% up to 22% per page. The final 895 props were cleared in three weeks by two engineers leaning heavily on Copilot coding agents. GitHub also had to decouple theming for its seven themes and high-contrast variants before pulling styled-components out entirely. A VS Code plugin and internal codemod cut the manual burden, and GitHub notes that styled-components entering maintenance mode reinforced the direction.

On Hacker News one commenter running a similar migration reported a 30% build time speed improvement and much better tree shaking on Next.js across a codebase over 1M lines. Others were sceptical about user impact, with one arguing that the reduction in size was not big enough to justify making all CSS names unreadable, adding that hashed class names make ad-blockers, custom CSS and browser extensions harder to build. A separate thread noted that CSS-in-JS can be made zero-runtime without moving to Modules at all.

GitHub joins a broader shift away from runtime CSS-in-JS. Linear recently completed its own 1,000-PR move from styled-components to Meta’s atomic StyleX library, citing similar render-time concerns after upgrading to React 18’s concurrent mode. Others using vanilla-extract or Tailwind have shifted style generation to build time entirely. The common thread is to pay the cost once at build, not on every request.

The Primer Design System is GitHub’s open-source component library, providing the foundational building blocks used across github.com. Teams following the same path can start from the Primer React v38 release notes and the migration guide for CSS variables, which covers the move from sx props to CSS Modules.

About the Author

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.