Urgent.News

What's breaking now, across thousands of outlets.

Tech

Improving site performance by shipping more CSS

GitHub's Primer Design System powers various features on the platform, such as buttons, banners, and breadcrumbs. However, the existing CSS-in-JS solution began to cause performance issues. Initial page loads took longer due to styles being initialized on the client, server-side rendering performance declined, and style updates grew out of control as component count increased.

To address these issues, the Primer team decided to switch to CSS Modules. This format allows writing and using native CSS features while maintaining the colocation and encapsulation that CSS-in-JS provided. With CSS Modules, styles are authored in a separate CSS file alongside the JavaScript source for the component. It treats all class names as local by default, preventing collisions and challenges that can arise from global selectors.

Importantly, styles are rolled up into CSS stylesheets, eliminating the need for client or server runtime behavior.

The transition to CSS Modules required updating every Primer component and GitHub component utilizing this technique. To minimize risks, the team adopted an incremental migration strategy. For each component, they added a new file that translated existing styles to CSS Modules, added the component to a feature flag that toggled between the new and old styles, and used visual regression tests to ensure identical snapshots between the CSS-in-JS and CSS Modules solutions.

The process involved gradual rollout to teams, GitHub staff, and all users, allowing the team to catch issues early and verify performance benefits.

By December 2024, all Primer components were migrated to CSS Modules. The team experienced significant performance improvements, including 55% less time to server-side render a page and 25% less time for components on a page to initialize. These results prompted further exploration of CSS Modules in other parts of GitHub and the eventual goal of dropping support for CSS-in-JS across the company.

One challenge in removing CSS-in-JS was the usage of the sx prop, which allowed styling and customizing components within Primer. The sx prop provided excellent TypeScript support, co-location of styles with components, and a convenient inline object for customization. However, it also had high runtime costs and scaling issues as the number of components using sx increased.

To mitigate these issues, the team created wrapper components in a transitive library called @primer/styled-react. This library allowed the use of sx in newly migrated components, enabling GitHub's UI codebase to continue consuming components through @primer/styled-react while the team realized performance gains. This approach enabled the migration of thousands of sx props without disrupting the GitHub UI codebase.

Written by urgent.news from GitHub Blog's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at github.blog →

More in Tech

When Redis goes down, does your app die?

The Problem: The App Dies There was an incident that caused our application to fail because our Redis cache went down. It was in the middle of moving to a larger compute instance to handle a higher…

  • Redis cache failure significantly impacted application experience
  • Resilient Cache-Aside approach implemented to handle exceptions
  • Circuit Breaker pattern improved app performance and user experience

Using fstab instead of autofs for a samba share

A few weeks ago, I borrowed a Raspberry Pi 4B from a friend. Since it wasn't going to be used for a while, I decided to set up a network storage for our home network.

  • Author used Samba for network storage on Fedora Server 38
  • Initial autofs and crypttab configuration failed due to race condition
  • Fstab permanently mounted drive, solved Samba access issue

Uptime Kuma on Fedora with Podman Quadlet

Over the weekend, I decided to set up Uptime Kuma on my mini-server. I needed a quick way to monitor some important work services, and Uptime Kuma’s Slack notifications make it easy to get alerts…

  • Uptime Kuma installed on Fedora mini-server for service monitoring
  • Podman Quadlet used to manage containers with declarative files
  • SELinux permissions adjusted and systemd service enabled via Quadlet

Claude tự chạy regression test app Flutter của mình trong lúc mình ngủ

Hồi trước mình làm ở một công ty ví điện tử màu hồng ở Việt Nam. Ở đó anh leader giới thiệu cho mình một tool viết automation test khá hay tên là Maestro.

  • Claude created Maestro, an AI-powered automation testing tool for Flutter apps.
  • He developed Maestro while working in a fintech company, impressed by its ease of use.

More from Sunday 27 September →