GitHub Primer's CSS Modules migration: guardrails before AI agents

GitHub halved server render time moving Primer to CSS Modules; agents cleared the last 900 sx props only because shims, flags and snapshots existed.

Card on GitHub Primer's move from CSS-in-JS to CSS Modules: 55% less server render time and the migration timeline.

GitHub cut server render time by more than half when Primer moved from CSS-in-JS to CSS Modules.

The last stretch is the part worth copying.

Removing the sx prop across github.com started at nearly 8,000 call sites. A rotation of eight engineers, with a VS Code plugin and a codemod, moved about 6,400 of them in six months. This April, two engineers and Copilot coding agents cleared the final 900 in three weeks.

What made that safe was built long before the agents showed up:

  • a wrapper package so old sx callers kept working,
  • a feature flag per component,
  • visual regression snapshots that had to match before rollout.

Even at zero sx props, seven themes still ran through styled-components. That took two more months.

Before you point agents at a migration, build four things:

  • a shim, a flag, a snapshot diff, a way back.

Agents can finish a migration. Guardrails decide whether they should start one.

Watch the video on LinkedIn ↗