What are the challenges of CSS-in-JS in the App Router?

Runtime CSS-in-JS libraries generate styles while components render in the browser, but Server Components never run in the browser and React streams HTML in chunks. So these libraries only work in Client Components, need a registry to inject styles during streaming, add JavaScript and render cost, and some are not fully compatible with concurrent rendering.

The specific problems

  1. No Server Component support: styled and css props rely on context and hooks, so every styled component becomes client code.
  2. Streaming SSR: styles must be emitted before the HTML that uses them in each streamed chunk. Libraries need useServerInsertedHTML integration, or users see unstyled content.
  3. Runtime cost: serializing styles, hashing class names and inserting <style> tags during render hurt INP and hydration time.
  4. Concurrent rendering: style injection in render conflicts with React's concurrent features; React recommends useInsertionEffect for libraries.
  5. Bundle size: the runtime ships to the browser.
  6. Library support: Emotion still lacks full App Router support at the time of the current docs; styled-components works with a registry but is in maintenance mode.

Supported options (per Next.js docs)

In Client Components: Ant Design, Chakra UI, Fluent UI, Kuma UI, MUI (with its App Router integration), Panda CSS, styled-jsx, styled-components, StyleX, Tamagui, tss-react and vanilla-extract.

Recommended direction

  • Zero-runtime, compile-time solutions (vanilla-extract, Panda CSS, StyleX, Kuma UI, Pigment CSS) extract static CSS at build time and work in Server Components.
  • Tailwind CSS and CSS Modules are the defaults the Next.js docs lean on.
  • Keep dynamic values in CSS variables set via style={{ "--x": value }} rather than generating new classes at runtime.

Code example

tsx
1// Problem: runtime CSS-in-JS forces a client boundary
2// "use client";
3// import styled from "@emotion/styled";
4// export const Card = styled.div`padding: 16px;`;
5
6// Zero-runtime alternative: vanilla-extract (compiled to static CSS at build time)
7// app/card.css.ts
8// import { style } from "@vanilla-extract/css";
9// export const card = style({ padding: 16, borderRadius: 12, background: "var(--surface)" });
10
11// app/card.tsx - works as a Server Component
12import { card } from "./card.css";
13
14export function Card({ children, accent }: { children: React.ReactNode; accent: string }) {
15 // Dynamic values through CSS variables, no runtime style generation
16 return (
17 <div className={card} style={{ "--accent": accent } as React.CSSProperties}>
18 {children}
19 </div>
20 );
21}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app