Lesson 28 of 30
A server-rendered Angular app ships real HTML on first paint — hydration is what turns that static markup into a live, interactive app without Angular tearing it down and rebuilding it first.
15 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
This topic is about judgment and practical tradeoffs more than a single right answer — a mock interview is the better way to test yourself on it.
Be interviewed on this →Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Server-side rendering means Angular runs your components on the server, produces real HTML, and sends that to the browser — so the user sees content immediately instead of a blank page waiting for JavaScript to load and run. But raw HTML isn't interactive: clicking a button in that server-rendered markup does nothing until Angular's client-side code takes over.
Hydration is that handoff. The naive approach would be for the client to just re-render everything from scratch and swap it in — but that means the DOM the user is already looking at gets destroyed and rebuilt, causing a visible flicker and losing things like scroll position or focus. Angular's modern hydration is non-destructive: the client-side app recognizes the server-rendered DOM that's already sitting in the page, attaches its event listeners and reactive machinery to those existing elements, and skips re-creating them. The app "wakes up" in place instead of being reborn.
// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideClientHydration, withEventReplay } from '@angular/platform-browser';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideClientHydration(withEventReplay()),
],
};
provideClientHydration() is the switch that turns on non-destructive hydration for the whole app — without it, an SSR'd Angular app would still fully re-render client-side and discard the server DOM, which is exactly the flicker-and-flash pattern hydration exists to avoid. withEventReplay() closes a specific gap: there's an unavoidable window between "HTML is visible" and "Angular's JavaScript has finished loading and attached its listeners," and if the user clicks a button during that window, a naive setup would just drop the click. Event replay buffers interactions that happen during that gap and replays them once the app is actually ready to handle them — so a fast click on a slow connection doesn't silently vanish.
withEventReplay() as optional polish. On a slow connection or a large page, the gap between "visible" and "interactive" can be long enough that real users click things during it — without event replay, those clicks are just lost, not queued.This is the same problem this platform's Next.js track covers under hydration and streaming — a server sends real markup first, and the client has to attach behavior to it without a jarring rebuild, and both frameworks converge on the same non-destructive strategy for the same reason. It also mirrors what React's own hydration lesson on this platform describes for hydrateRoot(): reusing existing DOM nodes instead of discarding and recreating them is the shared idea, even though the two frameworks implement the reconciliation differently underneath.