Introduction
GitHub, one of the world’s largest web applications, announced the completion of a three‑year effort to replace its CSS‑in‑JS stack (styled‑components) with native CSS Modules. The move delivered a 55% reduction in server‑side rendering (SSR) time and a 25% improvement in component initialization across its Primer design system.- --
Why GitHub Started with CSS‑in‑JS
- Early convenience: Styled‑components allowed developers to colocate styles with React components, enabling dynamic theming and runtime style generation.
- Design system integration: Primer leveraged the
sxprop andstyled-systemutilities to create a highly customizable UI. - Initial performance: At launch, the overhead was negligible compared to the overall page load budget.
The Scaling Problem Emerged in 2023
In 2023 the number of Primer components on key pages exploded, exposing three major pain points:
1. Slower first‑paint – each component required runtime style calculation on the server.
2. Growing SSR latency – the cumulative cost of evaluating styled‑components grew linearly with component count.
3. Theming complexity – supporting seven themes plus high‑contrast variants added extra runtime branches.
Choosing CSS Modules
The Primer team selected CSS Modules because they:- Keep native CSS features (media queries, cascade, inheritance) while providing local scoping.
- Allow styles to be bundled into static stylesheet files, eliminating any runtime style logic on the client or server.
- Preserve the co‑location pattern by placing a
.module.cssfile next to its component.
Migration Strategy
The migration was split into three disciplined phases, each guarded by feature flags to avoid breaking the live site.
Phase 1 – Reducing sx Prop Usage
- Engineers audited 7,760
sxusages. - Over six months, a rotation of eight engineers migrated 6,419 props to static class names.
- Early pages saw 3%‑22% SSR improvements, proving the hypothesis.
Phase 2 – Decoupling Theming
- GitHub supports seven themes and a high‑contrast variant, all originally powered by styled‑components.
- Two months of work extracted theme variables into CSS custom properties (
--color‑...). - Feature flags ensured a gradual rollout without visual regressions.
Phase 3 – Full Codemod & Copilot Assistance
- A custom VS Code plugin and an internal codemod automated the bulk of the conversion.
- The final 895
sxprops were cleared in three weeks by two engineers leaning heavily on GitHub Copilot coding agents. - By June 2026 the entire dot‑com codebase ran solely on CSS Modules; styled‑components,
styled-system, and thesxprop were removed.
Performance Gains
The engineering blog reports two concrete metrics on a representative Primer‑powered page:
- 55% reduction in SSR time (from X ms to Y ms).
- 25% faster component initialization on the client.
|----------------------|--------------------|----------------------------|
| Unnamed Primer page | 55% | 25% |
| Early rollout pages | 3% – 22% | — |
| Final migration | 1% – 22%* | — |
*Variation depends on page complexity and the number of migrated components.
Role of AI Assistance
- Copilot generated repetitive CSS‑Module import statements and class‑name mappings.
- AI‑driven suggestions accelerated the codemod validation, reducing manual review time by ~40%.
- The team credits AI agents for the rapid clean‑up of the last 895 props.
Lessons for Large‑Scale Web Apps
1. Measure before you refactor – GitHub’s detailed SSR benchmarks guided the migration priority.
2. Feature‑flag safely – Incremental rollout prevented user‑visible regressions.
3. Automate aggressively – Custom codemods and AI‑assisted tooling cut months of manual work.
4. Don’t chase hype – CSS‑in‑JS is still valuable for small apps; the decision hinges on runtime cost at scale.
5. Keep the design system flexible – By moving theme values to CSS variables, GitHub retained dynamic theming without runtime JavaScript.
Conclusion
GitHub’s three‑year journey from styled‑components to CSS Modules demonstrates that static CSS can outperform dynamic styling at massive scale. The migration delivered measurable performance wins, reduced runtime complexity, and showcased how AI tooling can accelerate large refactors. For organizations wrestling with similar scaling challenges, the case study offers a practical roadmap: audit, flag, automate, and iterate.- --
PEER OBSERVATIONS
Technical Discussion (0)
Join the Technical Discussion — Sign in or create an account to contribute observations and earn community points.