الانتقال إلى المحتوى
FrontendAngular· 6 دقائق للقراءة

Incremental Hydration: Pages Don't Have to Hydrate All at Once

A @defer block with a hydrate trigger is rendered on the server, but its code loads and hydrates only when the trigger fires, and early clicks are replayed. In Angular 22 it's on by default.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
  • Angular 22
محتويات المقال

A product page is server-rendered and appears quickly, but on a mid-range phone the "Add to cart" button responds late: the click is queued until the browser has downloaded and run the code for the review carousel, the specs table and the recommendations, none of which the user has scrolled to yet. The team's first fix is to wrap those sections in @defer (on viewport). The bundle shrinks, but the server-rendered HTML now has gray skeletons where the reviews used to be, and the page can shift when the real content replaces them.

The common misconception

The belief: a server-rendered page is all or nothing. The browser has to download the page's JavaScript and hydrate the whole component tree before any of it responds, so the only way to send less code is to defer content, and deferred content means placeholders in the server's HTML.

Both halves describe real behavior. With full hydration, the app hydrates as one tree, and the hydration guide notes that event listeners aren't attached until hydration completes. And the @defer guide says that by default, when rendering on the server, defer blocks "always render their @placeholder" and their triggers aren't invoked. The belief simply stops at those defaults.

What actually happens

A hydrate trigger turns @defer into a hydration boundary

adds a second kind of trigger to @defer. According to the guide, a hydrate trigger tells Angular to "load that defer block's dependencies during server-side rendering and render the main template rather than the @placeholder". So the server's HTML contains the real reviews.

In the browser, the block's dependencies are still deferred, and its content "stays dehydrated until its hydrate trigger fires". Dehydrated means the user sees the server's HTML, but no component code for that block has been downloaded or run: no constructor, no listeners, nothing reactive. It's a picture of the reviews, which is all a user who hasn't scrolled down needs.

The trigger downloads, hydrates, then replays

When the trigger fires, the block fetches its dependencies and hydrates its content, reusing the server's DOM like any other . If the user clicked inside the block before that, has queued the event: the guide says events that match listeners in your components "are queued up and replayed once the hydration process is complete". Incremental hydration enables event replay automatically.

The trade-off is latency on that first interaction: a click on a dehydrated block waits for its chunk to download. That's fine for a "Show all reviews" button and wrong for the main call to action.

It's already on in Angular 22

Since Angular 22, provideClientHydration() enables incremental hydration by default. withIncrementalHydration() is deprecated, with removal planned for v24, and withNoIncrementalHydration() opts out. Content without a hydrate trigger hydrates as before, so nothing changes until you add triggers.

TypeScript product-page.ts
import { Component } from '@angular/core';@Component({  selector: 'app-product-page',  imports: [ProductSummary, ProductSpecs, Reviews],  template: `    <app-product-summary />    <!-- The server renders only the skeleton here, and the page         shifts when the real reviews replace it in the browser -->    @defer (on viewport) {      <app-reviews />    } @placeholder {      <div class="reviews-skeleton"></div>    }    <!-- Static text, but its code ships and hydrates up front -->    <app-product-specs />  `,})export class ProductPage {}

The summary with the buy button stays eager, so it hydrates with the page. The reviews arrive in the HTML, cost nothing until the user scrolls to them, and hydrate in place without a layout shift. The specs never need code on the first load, so hydrate never keeps them as static HTML.

Choosing a trigger

Hydrate triggerHydrates whenGood for
hydrate on immediateRight after the non-deferred content has renderedContent needed soon, just not first
hydrate on idleThe browser is idle (requestIdleCallback)Secondary widgets
hydrate on viewportThe content enters the viewportSections below the fold
hydrate on interaction or hoverClick or keydown, or mouseover or focusinMenus, tabs, rarely used controls
hydrate whenA condition in the parent becomes truthyHydration driven by app state
hydrate neverNever, on the initial loadStatic content

A block can list several hydrate triggers separated by semicolons, and Angular hydrates it as soon as any of them fires.

Hydrate triggers only cover the first load

Hydration only applies to server-rendered content, so hydrate triggers only apply to the initial page load. When a user reaches the same page through a client-side navigation, the regular trigger runs, and the @placeholder is rendered first. That's why the example keeps both kinds of trigger and the placeholders, and why the guide says you still need a @placeholder. Nested blocks hydrate from the top-most dehydrated parent down, and hydrate never on a block keeps its whole subtree static.

How to apply it in your project

  1. Check your hydration configKeep provideClientHydration() without withNoIncrementalHydration(). Remove the deprecated withIncrementalHydration(), and withEventReplay(), which incremental hydration already enables.
  2. Find heavy sections below the foldLook for large components users rarely reach on the first screen: reviews, recommendations, comments and long tables.
  3. Add a hydrate trigger to each oneWrap each section in @defer with a regular trigger for client navigation and a hydrate trigger for the first load, and keep a @placeholder whose size matches the content.
  4. Test both pathsLoad the page directly to exercise the hydrate trigger, then reach it through a routerLink to exercise the regular trigger and the placeholder.

Key takeaways

  • Full hydration hydrates the page as one tree; incremental hydration splits it at @defer blocks with hydrate triggers.
  • With a hydrate trigger, the server renders the block's real content, and the browser keeps it as static HTML until the trigger fires.
  • Event replay queues clicks on dehydrated content and replays them after hydration.
  • In Angular 22, provideClientHydration() enables incremental hydration and event replay by default.
  • Hydrate triggers cover the initial load only; keep a regular trigger and a @placeholder for client-side navigation.

📚 المصادر

  1. Incremental Hydration — Angular
  2. Deferred loading with @defer — Angular
  3. Hydration: capturing and replaying events — Angular
  4. withIncrementalHydration — Angular
  5. withEventReplay — Angular

التعليقات (0)