这篇文章尚未翻译成中文,当前显示英语原文。
The real cost of hydration in a server-first blog
Server components remove JavaScript from the bundle, but the client boundary still ships state. Measure the boundary before optimizing the framework.
核心摘要 · TL;DR
Server components reduce client JavaScript only when the boundary is drawn carefully. The main costs are the serialized RSC payload, client component props and third-party scripts, not the framework itself.
Key facts
- A server component that passes a large object into a client component serializes that object into the payload.
- Hydration cost is paid per client component instance, not per page.
- Third-party scripts usually dominate the main-thread budget on content sites.
What actually ships
In a server-first app, the browser still downloads:
- the framework runtime
- client component code
- the serialized RSC payload
- props passed from server to client components
Only the first two are obvious in bundle reports. The payload and props are where regressions hide.
Draw the boundary around interaction
Start from what must respond on the client:
- vote buttons
- reading progress
- view tracking
- theme or language menus that need local state
Everything else — article body, table of contents, cards, related posts — can stay on the server. The boundary should follow interaction, not file structure.
The prop serialization trap
Passing a full post object into a client component serializes every field, including content. Pass the minimum: an id, a slug, a formatted count. A smaller prop surface reduces both payload size and re-render risk.
Measure three numbers
| Metric | Where | Why |
|---|---|---|
| Route JS transfer | browser network panel or build report | Shows the real shipped code |
| RSC payload size | HTML/stream size | Catches oversized props |
| Long tasks during load | performance trace | Shows hydration and script cost |
Track them per route template, not per page, so the numbers stay comparable.
Common mistakes
- Importing a markdown renderer into a client component.
- Passing server data through a client wrapper that does nothing.
- Loading analytics before the article is readable.
- Treating a fast first paint as a fast page.
Conclusion
Server components are a boundary tool, not a performance badge. Keep the client side small, measure the payload and make third-party scripts earn their place.
常见问题
Do server components eliminate hydration?
No. They remove server-rendered components from the client bundle, but any client component still hydrates with its props.
What should I measure first?
Measure the route's JavaScript transfer size, the RSC payload size and the main-thread work during load. Then decide whether the boundary is in the right place.
这篇文章对你有帮助吗?
你的评价会告诉其他读者这篇文章的可信度。
Senior data editor · InsightLog
Builds data pipelines and measurement systems, and writes about the context behind every number.
Markdown 原文: /zh/posts/server-components-hydration-cost/raw
引用来源: https://insightlog.site/zh/posts/server-components-hydration-cost
Continue reading
延伸阅读
在 Next.js App Router 中用服务端组件设计博客
以服务端组件为中心划分数据流,博客的缓存策略会变得简单。本文整理实际结构与常见陷阱。