Question presented to candidate: "We render our Angular app on the server, but users see the page flash and their first clicks do nothing. Explain what hydration is, what Angular means by non-destructive hydration, and what we should turn on."
What a strong answer should cover:
- Hydration: making server-rendered HTML interactive in the browser by attaching Angular to the existing DOM.
- Destructive vs non-destructive: old behaviour wiped the server DOM and re-rendered (flicker, wasted work); non-destructive hydration (v16 preview, stable v17) reuses the nodes.
- How to enable it:
provideClientHydration()in the app config; the server addsnghannotations and anng-statescript that the browser reads. - Event replay: user events captured before hydration are replayed afterwards.
- Incremental hydration:
@defer (hydrate on ...)keeps parts of the page dehydrated until needed; on by default in v22. - How to confirm it works: the dev-mode hydration log and the absence of flicker.
Clarifying questions expected:
- "Are we on a version with
provideClientHydration, or still on the older Universal setup?" - "Do the first clicks fail everywhere, or only on heavy pages that take long to boot?"
Code / implementation expected: Optional β the provider line, and one @defer block with a hydrate trigger.