Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ together; the short version:
The docs' home page is the exception to "the docs explain": its first screen
is the hook, a headline, the two ways on (get started, the live demo) and one
drawing, `src/app/home-race.ts`: one page sent whole and streamed, which is
the `race` figure in two lanes with the same made-up times. Keep the two in
step, and the buttons on the first screen.
the `race` figure in two lanes with the same parts in the same order and the
same made-up times. It adds hydration, in the colours of the other figures
(`figures/mock.css`): each part is hydrated half a second after it lands, the
whole page at once when it is sent whole, a part at a time when it is
streamed. Keep the two in step, and the buttons on the first screen.
- **Styles (demo and docs)**: both use the PushBased design system in
`libs/design-system/` (read its `README.md`). Use its tokens and the
`.pb-*` component classes and `.text-*` type styles; never hard-code colours,
Expand Down
40 changes: 27 additions & 13 deletions apps/docs/src/app/home-race.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { Component, signal } from '@angular/core';

/** The parts of the made-up page, top to bottom. */
/**
* The parts of the made-up page, top to bottom, in the `race` figure's order:
* the slowest part is in the middle, so the streamed page fills, and hydrates,
* out of order. A part that waits for data has a placeholder in the streamed page
* until it lands.
*/
const PARTS = [
{ id: 'product', label: 'Product' },
{ id: 'reviews', label: 'Reviews' },
{ id: 'recommendations', label: 'Recommendations' },
{ id: 'product', label: 'Product', waits: false },
{ id: 'recommendations', label: 'Recommendations', waits: true },
{ id: 'reviews', label: 'Reviews', waits: true },
];

/**
* The home page's hero: one product page sent whole and streamed, on one
* clock. A drawing, not a measurement: the product renders at once, the reviews
* take one second and the recommendations three, the times of the `race`
* figure (`figures/race.ts`) in "Why stream out of order".
* figure (`figures/race.ts`) in "Why stream out of order". A part lands as
* server HTML, and Angular hydrates it half a second later: the whole page in
* one go when it was sent whole, a part at a time when it was streamed, the
* reviews at the bottom before the recommendations above them.
*
* It is all CSS (`styles.css`, "The hero's animation"), so it plays in the
* prerendered page before Angular is there. It loops, so it can be paused; a
* reader who asked for reduced motion gets the frame at 1.5 s, standing still.
* reader who asked for reduced motion gets the frame at 1.25 s, standing still.
*/
@Component({
selector: 'docs-home-race',
Expand All @@ -29,7 +37,8 @@ const PARTS = [
<span class="race-blank">Blank page</span>
@for (part of parts; track part.id) {
<span class="race-part" [class]="'race-part--' + part.id">
<span class="race-ready">{{ part.label }}<i></i></span>
<span class="race-face race-html">{{ part.label }}<small>HTML</small></span>
<span class="race-face race-hydrated">{{ part.label }}<small>hydrated</small></span>
</span>
}
</div>
Expand All @@ -39,8 +48,11 @@ const PARTS = [
<div class="race-page race-page--streamed">
@for (part of parts; track part.id) {
<span class="race-part" [class]="'race-part--' + part.id">
<span class="race-loading">{{ part.label }}</span>
<span class="race-ready">{{ part.label }}<i></i></span>
@if (part.waits) {
<span class="race-face race-loading">{{ part.label }}<small>loading</small></span>
}
<span class="race-face race-html">{{ part.label }}<small>HTML</small></span>
<span class="race-face race-hydrated">{{ part.label }}<small>hydrated</small></span>
</span>
}
</div>
Expand All @@ -49,16 +61,18 @@ const PARTS = [
<div class="race-clock" aria-hidden="true">
<span class="race-track"><span class="race-elapsed"></span></span>
<span class="race-ticks"
><span>0 s</span><span>1 s</span><span>2 s</span><span>3 s</span></span
><span>0 s</span><span>1 s</span><span>2 s</span><span>3 s</span><span>4 s</span></span
>
</div>
<figcaption>
<span>
One page, sent both ways, on one clock.
<span class="visually-hidden">
Sent whole, the page is blank for three seconds, then all of it is there. Streamed, the
product is there at once, the reviews after one second and the recommendations after
three.
Sent whole, the page is blank for three seconds, then all of it is there as HTML, and
half a second later Angular hydrates all of it at once. Streamed, the product at the top
is there at once, the reviews at the bottom after one second and the recommendations
between them after three, and Angular hydrates each of them half a second after it
lands.
</span>
A drawing: the times are made up.
</span>
Expand Down
5 changes: 5 additions & 0 deletions apps/docs/src/app/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ import { DEMO } from './links';
whole, that is a blank page for three seconds. Streamed, the reader has the product straight
away and the reviews after one.
</p>
<p class="home-text">
Hydration follows the HTML. Sent whole, nothing on the page responds to a click until all of
it has arrived and Angular has hydrated all of it. Streamed, Angular hydrates each part as
it lands, so the product can be used while the reviews are still loading.
</p>
<p class="home-text">
Both pages are complete at the same moment: streaming does not make a slow request faster.
It stops the rest of the page, and the browser's work on styles, fonts and scripts, from
Expand Down
Loading
Loading