Course contentsShow
← React
Lesson 1950 of 2,39644. Styling ApproachesFree lesson

The Runtime CSS-in-JS Problem

Why runtime CSS-in-JS libraries like styled-components cause performance issues in React 18+ concurrent features.

The Runtime CSS-in-JS Problem

You'll learn: Why libraries like styled-components and Emotion create performance bottlenecks in modern React, especially with concurrent features.

The Core Issue

Runtime CSS-in-JS libraries generate and inject styles during component rendering. Every time a styled component renders, the library must:

  1. Parse the template literal or style object
  2. Generate unique class names
  3. Serialize styles into CSS strings
  4. Inject <style> tags into the document head

This work happens on the main thread during the render phase — exactly when React needs maximum performance.

Why React 18+ Makes It Worse

React 18's concurrent features (like Suspense, transitions, and streaming SSR) can start, pause, and restart rendering multiple times. With runtime CSS-in-JS:

  • The same styles might be recalculated multiple times during concurrent renders
  • Style injection can block the main thread during time-slicing
  • Server components can't use runtime CSS-in-JS at all (they serialize, not execute)
  • Streaming SSR becomes slower as styles must be computed before hydration

Analogy: Imagine a chef who must write down the recipe, buy ingredients, and cook the dish every single time someone orders — even for the same meal. Runtime CSS-in-JS "cooks" your styles fresh on every render instead of preparing them ahead of time.

The Alternative Path

Zero-runtime solutions (like vanilla-extract, Linaria, or compiled CSS Modules) move this work to build time, generating static CSS files. React never sees the styling logic — just class names.

Key Takeaway: Runtime CSS-in-JS adds serialization and injection work during the render phase, creating performance overhead that conflicts with React 18's concurrent rendering model. Zero-runtime alternatives eliminate this cost by moving style generation to build time.