# 部分水合

**部分水合**（Partial hydration），在基于岛屿的实现中，是一种 Web 渲染策略：服务器输出完整的 HTML 文档，客户端只对显式标记为可交互的区域附加 [JavaScript](https://www.edgepedia.org/zh/javascript) 事件处理，其余区域保持静态，不进行虚拟 DOM 协调，也不附加监听器。<sup>[1](https://www.islands-architecture.com/core-islands-architecture-hydration-models/understanding-partial-hydration/)</sup> 它颠覆了全页水合框架的默认做法——那些框架会为整个文档发送 JavaScript：水合变成一种按需选择（opt-in）的模型，只为可交互的 UI 组件发送 JavaScript，而页眉、页脚和文章正文保持为纯 HTML。<sup>[2](https://www.netlify.com/blog/2021/11/12/ship-javascript-where-it-counts-with-vite-partial-hydration/)</sup><sup> • </sup><sup>[3](https://www.gatsbyjs.com/docs/conceptual/partial-hydration/)</sup>

| 关键事实 | 详情 |
|---|---|
| 水合什么 | 只有显式标记为可交互的组件（在 Astro 中通过 `client:*` 指令标记）；未标记的组件永远不会被水合。<sup>[4](https://docs.astro.build/en/concepts/islands/)</sup> |
| 主要变体 | 岛屿架构（Astro）与选择性/流式水合（React、Angular）；可恢复性（Qwik、Google 的 Wiz、eBay 的 Marko）是一种相关的替代方案，而 Gatsby 使用基于 React 服务端组件的部分水合。<sup>[4](https://docs.astro.build/en/concepts/islands/)</sup><sup> • </sup><sup>[5](https://www.searchenginejournal.com/rehydration/485009/)</sup><sup> • </sup><sup>[3](https://www.gatsbyjs.com/docs/conceptual/partial-hydration/)</sup> |
| 负载效果 | 在一项博客基准测试中，基于岛屿的框架无论文章长度如何，都只发送恒定的 5.4–18.5 KB（gzip 后）JavaScript，而 SvelteKit 的全页水合在最长的文章上膨胀到 272 KB（Svelte 5）和 836 KB（Svelte 3）。<sup>[6](https://github.com/khromov/interactive-blogs-benchmark)</sup> |
| 交互性效果 | 带完全再水合的服务端渲染（SSR）即使改善了首次内容绘制（FCP），也可能显著损害总阻塞时间（TBT）和交互到下一次绘制（INP），因为页面看起来已就绪，但在脚本执行之前无法响应输入。<sup>[7](https://web.dev/articles/rendering-on-the-web)</sup> |
| 生产案例研究 | Evil Martians 迁移到 Astro 岛屿后，首页加载时 JavaScript 减少了 61%，从未压缩的 1,281 KB 降至 497 KB；延迟加载站点搜索模态框又在全站范围内去掉了 437 KB。<sup>[8](https://astro.build/case-studies/evil-martians/)</sup> |
| 可恢复性 | Qwik 将执行上下文（包括组件状态和事件处理函数引用）序列化为 HTML 中的 `data-*` 属性；客户端只加载被触发事件所引用的那个确切符号。<sup>[1](https://www.islands-architecture.com/core-islands-architecture-hydration-models/understanding-partial-hydration/)</sup> |

## 工作原理

在传统的带再水合的服务端渲染中，服务器发送完整的 HTML，从而实现较快的[首次内容绘制](https://www.edgepedia.org/zh/first-contentful-paint)；随后客户端下载并重新执行应用的组件模板，以重建组件树、恢复事件监听器并重建应用状态。<sup>[9](https://qwik.dev/docs/concepts/resumable/)</sup> 在这项工作完成之前，页面虽然渲染出来却无法响应：在移动设备上，这种延迟的交互性可能长达数分钟，令用户困惑和沮丧。<sup>[7](https://web.dev/articles/rendering-on-the-web)</sup>

**部分水合改变了工作单元。** 客户端只水合标记为可交互的区域；静态区域完全不保留 JavaScript，使其客户端足迹降至接近零。<sup>[1](https://www.islands-architecture.com/core-islands-architecture-hydration-models/understanding-partial-hydration/)</sup><sup> • </sup><sup>[7](https://web.dev/articles/rendering-on-the-web)</sup> 在 [Astro](https://www.edgepedia.org/zh/astro-web-framework) 中，把一个静态组件变成交互岛屿只需要一个 `client:*` 指令，之后 Astro 会自动构建并打包客户端 JavaScript；开发者还可以选择水合发生的时机，因此购买按钮会立即水合，而图片轮播只在滚动进入视野时才水合，从未滚动到它的用户就永远不必承担其开销。<sup>[4](https://docs.astro.build/en/concepts/islands/)</sup><sup> • </sup><sup>[10](https://thenewstack.io/astro-revs-up-static-sites-with-partial-hydration/)</sup>

**可恢复性用序列化取代重新执行。** Qwik 在服务端渲染期间收集监听器和组件边界信息，并将其序列化进 HTML，因此浏览器无需预先执行任何工作即可恢复；一个 `on:click` 属性包含了恢复该处理函数所需的全部信息。客户端运行时只加载被触发事件所引用的那个确切符号，而非整个组件子树。<sup>[9](https://qwik.dev/docs/concepts/resumable/)</sup><sup> • </sup><sup>[1](https://www.islands-architecture.com/core-islands-architecture-hydration-models/understanding-partial-hydration/)</sup> 页面加载时只运行一个约一千字节的加载器，它安装一个全局事件监听器，除此之外什么都不做；处理函数代码块按需获取。<sup>[11](https://www.islands-architecture.com/core-islands-architecture-hydration-models/astro-vs-qwik-partial-hydration-tradeoffs/)</sup> Qwik 的文档直截了当地界定了这一区别：重新执行组件模板正是水合的本质，而水合之所以昂贵，是因为它既需要下载又需要执行这些模板；Qwik 应用不做水合，它们做的是恢复。<sup>[9](https://qwik.dev/docs/concepts/resumable/)</sup>

## 变体与实现

**岛屿架构**将每个可交互组件视为一个独立的岛屿，与页面其余部分分开水合。Astro 推广了这一模式（该词由 Sylor-Miller 首创），Astro 也是第一个内置选择性水合的主流 JavaScript Web 框架。<sup>[4](https://docs.astro.build/en/concepts/islands/)</sup> Astro 在构建时默认剥离所有客户端 JavaScript，同时允许开发者用 React、Preact、[Svelte](https://www.edgepedia.org/zh/svelte)、Vue、SolidJS、AlpineJS 或 Lit 编写岛屿。<sup>[10](https://thenewstack.io/astro-revs-up-static-sites-with-partial-hydration/)</sup>

**选择性水合**保持单一应用树，但按需水合其中的部分。Angular 的实现依赖流式传输：组件流式传入时保持未水合状态，直到该组件的流式传输完成，然后才进行水合。<sup>[12](https://thenewstack.io/angulars-approach-to-partial-hydration/)</sup>

**可恢复性**被 Qwik 使用，在工业界则被 Google 的内部框架 Wiz（用于搜索和相册）以及 eBay 的 Marko（将可恢复性作为一项特性加入）使用；Wiz 被称为最早的可恢复框架，并启发了 Qwik。<sup>[5](https://www.searchenginejournal.com/rehydration/485009/)</sup><sup> • </sup><sup>[12](https://thenewstack.io/angulars-approach-to-partial-hydration/)</sup>

**React 服务端组件提供了通往同一结果的另一条路径。** Gatsby 通过 React 服务端组件而非岛屿架构实现部分水合；最终结果——交互性岛屿——是相同的，但机制不同。<sup>[3](https://www.gatsbyjs.com/docs/conceptual/partial-hydration/)</sup> React 服务端组件维护单一根节点，并将服务端组件的虚拟节点作为数据序列化进 HTML，从而对应用进行水平拆分，而部分水合则将应用垂直拆分为岛屿。<sup>[13](https://www.builder.io/blog/hydration-tree-resumability-map)</sup> React 服务端框架采用基于指令的方式：标记了 `"use hydrate"` 指令的组件被渲染为普通的服务端 HTML，为该岛屿写入一份单独的 RSC 负载，之后它作为局部的非根出口（outlet）被水合。<sup>[14](https://react-server.dev/features/hydration-islands)</sup>

## 数据说话

**负载大小。** 在交互式博客基准测试中，基于岛屿的框架无论文章长度如何，都只发送恒定的 5.4–18.5 KB（gzip 后）JavaScript；唯一增长的是 HTML。[SvelteKit](https://www.edgepedia.org/zh/sveltekit) 的全页水合在最长的文章上，Svelte 5 膨胀到 272 KB，Svelte 3 膨胀到 836 KB。<sup>[6](https://github.com/khromov/interactive-blogs-benchmark)</sup> 同一基准测试发现，岛屿方案的平均 [Lighthouse](https://www.edgepedia.org/zh/lighthouse) 得分为 89–91，LCP 为 2.6–2.7 秒，TBT 为 30–77 毫秒；而 SvelteKit 2022 的得分为 60，LCP 为 7.9 秒，TBT 为 518 毫秒；Svelte 5 改进了全页模型，将最长文章的得分从 31 提升到 58，并将 LCP 从 14.9 秒降至 7.8 秒。<sup>[6](https://github.com/khromov/interactive-blogs-benchmark)</sup>

**框架对比。** 在 Sparkbox 对同一 React 组件的 Lighthouse 对比中，Next.js 得分为 88，TTI 为 1.7 秒，TBT 为 180 毫秒，LCP 为 1.7 秒；Astro 得分为 100，TTI 为 0.3–0.4 秒，TBT 为 0 毫秒，LCP 为 0.4 秒；一个 Qwik 应用得分为 100，TTI 为 0.5 秒，TBT 为 0 毫秒，LCP 为 0.5 秒，它使用基于 Rust 的优化器将应用状态序列化，从而消除水合。<sup>[15](https://sparkbox.com/foundry/ui_rendering_frameworks_next.js_astro_qwik_rendering_strategies_tested_time_to_interactive_total_blocking_time_largest_contentful_paint_measured)</sup>

**现场数据。** Astro 2023 年对真实站点核心 Web 指标（Core Web Vitals）的分析发现，Astro 是唯一一个超过 50% 的站点通过 Google CWV 评估的框架，而 Next.js 和 [Nuxt](https://www.edgepedia.org/zh/nuxt) 分别约为四分之一和五分之一通过，全站点平均通过率为 40.5%。在交互到下一次绘制（INP）上，没有框架达到 80% 的通过率，不过每个框架在首次输入延迟（FID）上都超过了 80%；Astro 最接近，为 68.8%。报告发现，发送更少 JavaScript 的站点往往表现更好，同时提醒说，不能确信地将框架选择本身认定为原因。<sup>[16](https://astro.build/blog/2023-web-framework-performance-report/)</sup>

**服务端岛屿与部分预渲染。** 在 Astro 对其服务端岛屿演示与 Next.js 部分预渲染（PPR）演示进行的 WebPageTest 对比中，服务端岛屿的 TTFB 为 0.766 秒对 0.838 秒，FCP 为 1.251 秒对 1.740 秒，LCP 为 1.405 秒对 1.740 秒，TBT 为 0.018 秒对 0.093 秒，在重复运行中服务端岛屿的 LCP 约快 20%。<sup>[17](https://astro.build/blog/astro-4120/)</sup>

**该测什么。** 专家指导意见认为，部分水合应通过测量主线程成本降低来验证：[可交互时间](https://www.edgepedia.org/zh/time-to-interactive)（TTI）和[总阻塞时间](https://www.edgepedia.org/zh/total-blocking-time)（TBT）是直接的性能指标，而打包体积只是一个代理指标。<sup>[1](https://www.islands-architecture.com/core-islands-architecture-hydration-models/understanding-partial-hydration/)</sup>

## 与全量水合及其他方案的比较

全页再水合的核心问题在于外观与就绪之间的差距：它即使改善了 FCP，也可能显著损害 TBT 和 INP，因为某些交互特性在客户端脚本执行并附加事件处理函数之前可能无法响应输入。真实网站指标表明，出于这一原因，带再水合的服务端渲染很少是最佳选择。<sup>[7](https://web.dev/articles/rendering-on-the-web)</sup> 水合整个页面还会为页眉或页脚等静态部分发送 JavaScript，而部分水合只为可交互部分发送 JavaScript，从而改善可交互时间。<sup>[3](https://www.gatsbyjs.com/docs/conceptual/partial-hydration/)</sup>

一项对水合模型的比较按工作发生的时间和成本对策略进行了排序：全量水合以全树主线程成本阻塞交互性；部分水合按岛屿推迟工作，对 TTI 影响小；可恢复性在每个处理函数的首次用户事件时触发，成本接近于零，只加载单个处理函数符号。<sup>[1](https://www.islands-architecture.com/core-islands-architecture-hydration-models/understanding-partial-hydration/)</sup>

**Next.js 部分预渲染**从服务端解决同一目标：PPR 是一种在同一路由中组合静态和动态内容的渲染策略，在改善初始页面性能的同时支持个性化的动态数据。<sup>[18](https://nextjs.org/docs/15/app/getting-started/partial-prerendering)</sup> Astro 的服务端岛屿与 PPR 有着相同的目标——提高页面可缓存性——但机制不同：服务端岛屿不像 PPR 那样在服务器上发起对源站的请求，而是从浏览器发起，因此它们绘制更早，但可能比 PPR 完成得更晚。<sup>[17](https://astro.build/blog/astro-4120/)</sup>

## 成本、权衡与不适用场景

**序列化开销。** 在大多数服务端渲染方案下，UI 所依赖的数据被序列化进嵌入页面的 script 标签；由于这与 HTML 大量重复，再水合可能导致的问题不止是交互性延迟。<sup>[7](https://web.dev/articles/rendering-on-the-web)</sup> 在可恢复性模型中，权衡转移到了标记本身：Qwik 的加载时 JavaScript 保持恒定，而其 HTML 随序列化状态增长。<sup>[11](https://www.islands-architecture.com/core-islands-architecture-hydration-models/astro-vs-qwik-partial-hydration-tradeoffs/)</sup>

**岛屿隔离。** 每个岛屿有自己的上下文和 React 树，因此岛屿之间共享上下文或冒泡事件需要自定义逻辑，Gatsby 的文档将岛屿描述为不适合[单页应用](https://www.edgepedia.org/zh/single-page-application)，理由是页面间导航可能更迟缓。<sup>[3](https://www.gatsbyjs.com/docs/conceptual/partial-hydration/)</sup> 与 Qwik 相关的分析从另一方向提出了同样的观点：岛屿必须手动创建，并作为独立的子应用运行，可能妨碍应用各部分之间的通信。<sup>[13](https://www.builder.io/blog/hydration-tree-resumability-map)</sup> 部分再水合还带来缓存挑战，而客户端导航意味着不能假定应用非交互部分的服务端渲染 HTML 在未进行整页加载的情况下可用。<sup>[7](https://web.dev/articles/rendering-on-the-web)</sup>

**不适用内容。** Astro 自己对服务端岛屿与 PPR 的比较说，它们适用于电子商务，但可能不会用于社交网络信息流。<sup>[17](https://astro.build/blog/astro-4120/)</sup> 破坏性再水合会销毁并重绘服务端内容，对 CLS、LCP 和 FID 等核心 Web 指标产生负面影响。<sup>[12](https://thenewstack.io/angulars-approach-to-partial-hydration/)</sup>

## 近期发展

Astro 4.12（2024）预览了服务端岛屿，它允许按需单独渲染动态或个性化岛屿，而不牺牲页面其余部分的性能，其演示受到 Next.js 部分预渲染的启发。<sup>[17](https://astro.build/blog/astro-4120/)</sup><sup> • </sup><sup>[19](https://docs.astro.build/en/guides/server-islands/)</sup> 标记了 `server:defer` 的岛屿被拆分为各自特殊的路由，由脚本在运行时获取。<sup>[17](https://astro.build/blog/astro-4120/)</sup> 研究也沿着同一方向推进：一篇 2025 年的 arXiv 论文为 React 提出了模块化渲染与自适应水合（MRAH），认为水合文章正文等静态内容是浪费的，因为并非页面的所有部分都需要客户端交互性。<sup>[20](https://arxiv.org/html/2504.03884)</sup>

## 争论与局限

最尖锐的分歧在于可恢复性的优势。与 Qwik 相关的分析将可恢复性描述为一种 O(1) 架构，其中 JavaScript 的数量与组件数量无关，因为事件处理函数位于根部，启动时不执行任何用户代码；而水合从根本上说是一次 O(N) 的树遍历；同一作者认为，基于水合的框架不经过根本性的架构变革就无法变得可恢复。<sup>[13](https://www.builder.io/blog/hydration-tree-resumability-map)</sup> 然而，权衡是双向的：Astro 的成本随水合岛屿的数量和大小而扩展，这对交互性的广度不利，对静态内容的体量有利；而 Qwik 的成本随序列化状态的体量而扩展，这对交互性广度有利，对状态繁重的页面不利。<sup>[11](https://www.islands-architecture.com/core-islands-architecture-hydration-models/astro-vs-qwik-partial-hydration-tradeoffs/)</sup>

## References

1. [Understanding Partial Hydration, IslandsArch](https://www.islands-architecture.com/core-islands-architecture-hydration-models/understanding-partial-hydration/)
2. [How to build speedy sites with Vite + partial hydration, Netlify](https://www.netlify.com/blog/2021/11/12/ship-javascript-where-it-counts-with-vite-partial-hydration/)
3. [Partial Hydration, Gatsby Docs](https://www.gatsbyjs.com/docs/conceptual/partial-hydration/)
4. [Islands architecture, Astro Docs](https://docs.astro.build/en/concepts/islands/)
5. [Rehydration For Client-Side Or Server-Side Rendering, Search Engine Journal](https://www.searchenginejournal.com/rehydration/485009/)
6. [interactive-blogs-benchmark, GitHub](https://github.com/khromov/interactive-blogs-benchmark)
7. [Rendering on the Web, web.dev](https://web.dev/articles/rendering-on-the-web)
8. [Affordable and Fast Migration, Astro case study](https://astro.build/case-studies/evil-martians/)
9. [Resumable, Qwik Documentation](https://qwik.dev/docs/concepts/resumable/)
10. [Astro Revs Up Static Sites with Partial Hydration, The New Stack](https://thenewstack.io/astro-revs-up-static-sites-with-partial-hydration/)
11. [Astro vs Qwik Trade-offs, IslandsArch](https://www.islands-architecture.com/core-islands-architecture-hydration-models/astro-vs-qwik-partial-hydration-tradeoffs/)
12. [Angular's Approach to Partial Hydration, The New Stack](https://thenewstack.io/angulars-approach-to-partial-hydration/)
13. [Hydration is a tree, Resumability is a map, Builder.io](https://www.builder.io/blog/hydration-tree-resumability-map)
14. [Hydration Islands, React Server](https://react-server.dev/features/hydration-islands)
15. [The Rendering Strategies of the Next.js, Astro, and Qwik Frameworks Compared, Sparkbox](https://sparkbox.com/foundry/ui_rendering_frameworks_next.js_astro_qwik_rendering_strategies_tested_time_to_interactive_total_blocking_time_largest_contentful_paint_measured)
16. [2023 Web Framework Performance Report, Astro](https://astro.build/blog/2023-web-framework-performance-report/)
17. [Astro 4.12: Server Islands, Astro Blog](https://astro.build/blog/astro-4120/)
18. [Partial Prerendering, Next.js 15 docs](https://nextjs.org/docs/15/app/getting-started/partial-prerendering)
19. [Server islands, Astro Docs](https://docs.astro.build/en/guides/server-islands/)
20. [Improving Front-end Performance through Modular Rendering and Adaptive Hydration (MRAH) in React Applications, arXiv](https://arxiv.org/html/2504.03884)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Web development and web-platform technologies › Rendering and delivery techniques

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/partial-hydration

English original: https://www.edgepedia.org/partial-hydration
