Improving site performance by shipping more CSS
GitHub migrated its Primer Design System and the github.com codebase from styled-components CSS-in-JS to CSS Modules, removing runtime styling costs on client and server. Primer components moved first, each behind a feature flag and checked against visual regression snapshots, which cut server-side render time by 55% and component initialization by 25%. A wrapper package, @primer/styled-react, kept the legacy `sx` prop working during the transition. About 7,760 `sx` props were then migrated with a VS Code plugin, codemods and later Copilot coding agents, followed by decoupling theming, and dotcom reached 100% CSS Modules in June 2026 without breakage.
Related posts
- Styling Linear for the future with StyleX
Linear mediumAdept
Linear migrated its React apps from styled-components to Meta's StyleX over more than 1,000 PRs. It moved style generation to build time and made styling contracts between components explicit and enforced. The work combined a deterministic codemod, narrowly scoped coding agents and manual review, starting with leaf components while both systems coexisted. Oxlint rules and a type-aware cross-file checker enforce `sx` prop propagation, merge precedence and design tokens, with CSS Modules kept as an escape hatch. Runtime-generated LCH themes were kept by injecting StyleX's hashed variable names per ThemeProvider, and removing runtime style injection cut main-thread CPU work by roughly 20–35% on view-heavy pages.
- Why We Ripped Twin out of 400+ Components
Railway mediumAdeptRailway replaced twin.macro with vanilla Tailwind across 400+ React components, which removed the last dependency on Babel and let the monorepo move fully to SWC. Dev cold starts dropped from ~35s to ~1.5s, a full build from 220s to 42s, and CI from 4-6 to 2-4 minutes. The migration took ~30 PRs with a codemod and custom helpers. Nested selectors moved to Tailwind-processed CSS files, theme() calls became CSS variables, and Twin's inline-style precedence and automatic merging were handled by migrating pages first and core components last, using `!` overrides and tailwind-merge.
- StyleX: A Styling Library for CSS at Scale
Meta Engineering mediumAdeptStyleX is Meta's build-time CSS-in-JS compiler that extracts style objects into collision-free atomic CSS, replacing the earlier cx system and cutting CSS size by 80% across Facebook, Instagram, WhatsApp and others. A Babel plugin hashes each property-value pair into a class, caches per file, and uses deterministic hashes for defineVars/defineConsts so it never reads imported modules. Merging is predictable (last style wins), and shorthand/longhand, pseudo-class and media-query conflicts are resolved by computing numeric priorities enforced via @layer or a polyfill. Constraints such as banning global and descendant selectors prevent styling at a distance, while stylex.when, dynamic styles via CSS variables, and theming APIs keep it expressive.
- How we use Web Components at GitHub
GitHub Engineering mediumAdeptGitHub moved from jQuery to native Web Components starting in 2014 and now ships dozens of custom elements such as <include-fragment>, <details-dialog> and <relative-time>. Engineers author components in the Rails monolith with Catalyst, a TypeScript decorator library, paired one-to-one with ViewComponent on the server, and enforce practices with ESLint plugins and ratchet tests that block deprecated patterns like facebox. Proven components are generalized, stripped of Catalyst and published as dependency-free, style-free open-source elements with TypeScript definitions. One example is <typing-effect>, built in under 40 lines to avoid a fivefold bundle-size increase from typed.js.
- The uphill climb of making diff lines performant
GitHub Engineering mediumAdeptGitHub rebuilt the React diff-line components in the pull request Files changed tab after large PRs pushed the JavaScript heap past 1 GB, DOM counts above 400,000 and INP to unusable levels. The v2 design cut per-line React components from eight to two, replaced per-line event handlers with a single top-level handler keyed on data attributes, and moved commenting and menu state into conditionally rendered children. It also confined useEffect to the file level and switched to O(1) Map-based lookups. On a 10,000-line split diff this cut rendered components by 74%, memory by about 50% and INP from ~450 ms to ~100 ms. For p95+ PRs, TanStack Virtual windowing gave a 10x heap and DOM reduction and 40–80 ms INP, supplemented by cheaper CSS selectors, GPU transforms, partial hydration and progressive diff loading.