Files
2nd/10_Wiki/Topics/Domain_Programming/Frontend/Styled Components v6.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

6.7 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-styled-components-v6 Styled Components v6 10_Wiki/Topics verified self
styled-components
sc-v6
CSS-in-JS
none A 0.9 applied
frontend
css-in-js
react
styled-components
2026-05-10 pending
language framework
typescript react

Styled Components v6

매 한 줄

"매 React-runtime CSS-in-JS 의 v6 modernization". 2023 release — stylis v4 (5x faster), transient props ($-prefix) 의 default, native transient, drop legacy babel-plugin in favor of SWC plugin. 2026 현재 RSC-incompatible 의 큰 단점 — Next.js App Router 사용 시 zero-runtime alternatives (Linaria/Vanilla Extract/Panda) 의 dominant.

매 핵심

매 v6 변경

  • stylis v4: parser rewrite, 5x faster, smaller bundle.
  • as polymorphic prop: typed properly with TS generics.
  • $prop transient: forwarded to component but not DOM attr (was opt-in, now norm).
  • No babel-plugin needed: SWC/Vite plugin 의 standard.
  • Drop: .extend, primary-theme prop forwarding, IE11.

매 RSC limitation

  • styled-components 의 React Server Components 와 incompatible — runtime stylesheet injection requires client.
  • Next.js App Router 의 'use client' boundary required everywhere using styled.
  • Mitigation: StyleRegistry + useServerInsertedHTML for SSR streaming.

매 응용

  1. Design system component library (theming via ThemeProvider).
  2. Conditional styling via props (variant, size).
  3. Animation via keyframes helper.

💻 패턴

Basic styled component

import styled from 'styled-components';

const Button = styled.button<{ $primary?: boolean; $size?: 'sm' | 'md' | 'lg' }>`
  padding: ${({ $size }) => ({ sm: '4px 8px', md: '8px 16px', lg: '12px 24px' }[$size ?? 'md'])};
  background: ${({ $primary, theme }) => $primary ? theme.colors.primary : 'transparent'};
  color: ${({ $primary, theme }) => $primary ? '#fff' : theme.colors.text};
  border: 1px solid ${({ theme }) => theme.colors.border};
  border-radius: 4px;
  cursor: pointer;
  &:hover { opacity: 0.9; }
`;

<Button $primary $size="lg">Click</Button>

Theme + TypeScript

// styled.d.ts
import 'styled-components';
declare module 'styled-components' {
  export interface DefaultTheme {
    colors: { primary: string; text: string; border: string; bg: string };
    space: (n: number) => string;
  }
}

// theme.ts
export const theme: DefaultTheme = {
  colors: { primary: '#0066cc', text: '#222', border: '#ddd', bg: '#fff' },
  space: n => `${n * 4}px`,
};

<ThemeProvider theme={theme}><App /></ThemeProvider>

Polymorphic as

const Box = styled.div<{ $padded?: boolean }>`
  padding: ${({ $padded }) => $padded ? '16px' : 0};
`;

// Render as <a> with proper typing
<Box as="a" href="/x" $padded>Link</Box>

// Component composition
const Card = styled(Box)`
  border: 1px solid #ddd;
  border-radius: 8px;
`;

Keyframes + animation

import styled, { keyframes } from 'styled-components';

const spin = keyframes`
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
`;

const Spinner = styled.div`
  width: 24px;
  height: 24px;
  border: 2px solid #ddd;
  border-top-color: #0066cc;
  border-radius: 50%;
  animation: ${spin} 1s linear infinite;
`;

Next.js App Router SSR setup

// app/registry.tsx
'use client';
import { useState } from 'react';
import { useServerInsertedHTML } from 'next/navigation';
import { ServerStyleSheet, StyleSheetManager } from 'styled-components';

export function StyledRegistry({ children }: { children: React.ReactNode }) {
  const [sheet] = useState(() => new ServerStyleSheet());

  useServerInsertedHTML(() => {
    const styles = sheet.getStyleElement();
    sheet.instance.clearTag();
    return <>{styles}</>;
  });

  if (typeof window !== 'undefined') return <>{children}</>;
  return <StyleSheetManager sheet={sheet.instance}>{children}</StyleSheetManager>;
}

// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html><body>
      <StyledRegistry>{children}</StyledRegistry>
    </body></html>
  );
}

Global styles + reset

import { createGlobalStyle } from 'styled-components';

const GlobalStyle = createGlobalStyle`
  *, *::before, *::after { box-sizing: border-box; }
  body {
    margin: 0;
    font-family: ${({ theme }) => theme.fonts.body};
    background: ${({ theme }) => theme.colors.bg};
  }
`;

Variants via css helper

import styled, { css } from 'styled-components';

const variants = {
  primary: css`background: #0066cc; color: #fff;`,
  ghost: css`background: transparent; border: 1px solid #0066cc; color: #0066cc;`,
  danger: css`background: #cc0000; color: #fff;`,
};

const Button = styled.button<{ $variant: keyof typeof variants }>`
  padding: 8px 16px;
  border-radius: 4px;
  ${({ $variant }) => variants[$variant]}
`;

매 결정 기준

상황 Approach
Existing styled-components codebase stay on v6
Next.js App Router (greenfield) Vanilla Extract / Panda CSS / Tailwind
Component library (npm package) v6 fine OR Stitches/VE (zero-runtime)
Performance-critical (LCP) zero-runtime CSS (Linaria/VE)
Need RSC NOT styled-components

기본값: 2026 greenfield React → Tailwind or Vanilla Extract. Existing styled-components codebase → upgrade to v6, plan migration if RSC needed.

🔗 Graph

🤖 LLM 활용

언제: existing SC codebase, design system library with runtime theming, Pages Router Next.js. 언제 X: RSC-heavy app, performance-critical (LCP), greenfield 2026 — recommend zero-runtime alternative.

안티패턴

  • Non-transient props leaking to DOM: <Button primary><button primary> warning. Use $primary.
  • styled() inside render body: new component each render → tree thrash + cache miss.
  • No ThemeProvider but using theme: undefined theme errors.
  • Forgetting StyleRegistry on SSR: FOUC + hydration mismatch.
  • Mixing styled-components and Tailwind: specificity hell.

🧪 검증 / 중복

  • Verified (styled-components v6 changelog, official docs, Next.js styling guide 2025).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — full canonical (v6 changes + RSC limit + SSR registry + patterns)