styled-components 와 emotion 이 고생하는 이유
둘 다 JavaScript 통해 runtime 에 style inject. Server Component 가 client 에 JS 0 ship; runtime CSS-in-JS 가 Server Component 에서 작동 못 함. Directive boundary 가 hard wall.
| 접근 | Server Component | Client Component |
|---|---|---|
| CSS Module | ✅ | ✅ |
| Tailwind CSS | ✅ | ✅ |
| styled-components | ❌ | ✅ (with registry) |
| emotion | ❌ | ✅ (with registry) |
Registry pattern
CSS-in-JS 유지해야 하면, server rendering 동안 style collect 해서 response 에 flush 하는 Client "style registry" 로 app wrap. Performance 가 영원히 내는 세금.
깔끔한 답
새 project 위해선 Tailwind 또는 CSS Module. 어디서든 돌고 runtime 비용 0.