Streamed hydration, step by step

This page is one HTTP response that arrives in pieces. Each box says which piece it came in, what it is waiting for, and whether Angular has taken it over yet. The event log records each step as it happens. The docs take a real page's response apart the same way, in One response, flush by flush.

The server's data takes 0 ms (A), 0 ms (D), 0 ms (B) and 0 ms (C). Reload to watch it again, or change the speed:

No delay: every request finishes before the server takes the shell, so the data is already in it. The boxes below describe the streamed case; here every block arrives filled in the shell, and only an empty chunk marked done follows.

shell

1 · The shell

Everything outside the @defer blocks below is the shell: this text, every box's frame and heading, and the placeholders inside the blocks. The server rendered it once the route was in place, without waiting for the data, and sent it in the first flush, with an inline runtime and the app's script at the end. The response stays open, and Angular starts and hydrates the shell while the rest is still on its way.

Server HTML, not hydrated yet. Angular hydrates it as soon as main.ts has loaded, without waiting for the end of the response.

@defer · hydrate when a()

2 · Block A hydrates as soon as its own data is there

The frame of this box is shell. Its contents are a @defer block: when data A is ready, after 0 ms, the server renders the block again and streams it as a chunk, a <template> plus a script. The script swaps the new markup in and hands data A to the app. That makes a() true, so Angular hydrates the block right away, while B, C and D are still loading.

Server HTML, not hydrated yet. Nothing here responds to events until Angular hydrates it.

Data A: answered by the server after 0 ms. This markup was rendered on the server and arrived in a chunk.

@defer · hydrate when b()

3 · Block B, with block C nested inside

Data B takes 0 ms. Block C sits inside block B's contents, so it doesn't exist until B's chunk brings it, still showing its own placeholder. When data C arrives, at 0 ms, the server sends block C by itself. It can still be swapped in, even though Angular has already hydrated block B around it.

Server HTML, not hydrated yet. Nothing here responds to events until Angular hydrates it.

Data B: answered by the server after 0 ms.

@defer · hydrate when c()

Block C, nested

Server HTML, not hydrated yet. Nothing here responds to events until Angular hydrates it.

Data C: answered by the server after 0 ms. This chunk carried block C alone, not block B again.

@defer · hydrate on idle

4 · Block D waits for the whole stream

Data D is ready after 0 ms, before B and C, and its chunk arrives then. But hydrate on idle says nothing about data: the browser could go idle before the chunk lands, and Angular would hydrate the placeholder. So the client keeps this block out of Angular's hands until the stream is done, and only then lets the trigger fire. Watch it stay "not hydrated" after its content has arrived.

Server HTML, not hydrated yet. Its content is here, but its trigger is hydrate on idle, so the client holds it until the stream is done.

Data D: answered by the server after 0 ms.

no block

5 · Outside any block: never in the server HTML

The quotes below show data A, just like block A, but they are not inside a @defer block. They belong to the shell, which went out before data A arrived and is never sent again. So the server HTML has empty quotes, and the text appears only because Angular renders it in the browser once data A arrives. The response inspector shows the empty quotes in the shell. (With no delay, data A is ready before the shell is taken, so the quotes are filled in the server HTML too.)

“Data A arrived after 0 ms.”

shell

6 · Requests the browser sent: 0

The page asks for all four pieces of data in the browser too. A request the server is already making is held back until its response arrives on the stream, then answered from transfer state, so the browser never fetches it. If this number goes above 0, the browser fetched something itself. That happens when the stream breaks off before all the data has arrived: the client then releases its held requests and lets them go to the network.