diff --git a/AGENTS.md b/AGENTS.md index 99423a0..d4b53d2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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, diff --git a/apps/docs/src/app/home-race.ts b/apps/docs/src/app/home-race.ts index 7c1d3b4..fa78b20 100644 --- a/apps/docs/src/app/home-race.ts +++ b/apps/docs/src/app/home-race.ts @@ -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', @@ -29,7 +37,8 @@ const PARTS = [ Blank page @for (part of parts; track part.id) { - {{ part.label }} + {{ part.label }}HTML + {{ part.label }}hydrated } @@ -39,8 +48,11 @@ const PARTS = [
@for (part of parts; track part.id) { - {{ part.label }} - {{ part.label }} + @if (part.waits) { + {{ part.label }}loading + } + {{ part.label }}HTML + {{ part.label }}hydrated }
@@ -49,16 +61,18 @@ const PARTS = [
One page, sent both ways, on one clock. - 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. A drawing: the times are made up. diff --git a/apps/docs/src/app/home.ts b/apps/docs/src/app/home.ts index 559cdd4..0b993ae 100644 --- a/apps/docs/src/app/home.ts +++ b/apps/docs/src/app/home.ts @@ -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.

+

+ 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. +

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 diff --git a/apps/docs/src/styles.css b/apps/docs/src/styles.css index e881acd..2bf9b31 100644 --- a/apps/docs/src/styles.css +++ b/apps/docs/src/styles.css @@ -1166,11 +1166,18 @@ pre.mermaid[data-processed] svg { /* * The hero's animation (home-race.ts): one page sent whole and streamed, on - * one clock. A cycle is 6 s: the 3 s the page takes, a hold, and a reset. Every + * one clock. A cycle is 8 s: the 4 s on the clock, a hold, and a reset. Every * animation runs on that cycle, so they stay in step; the keyframes hold the - * times (0.1 s is 1.6%, 1 s is 16.6%, 3 s is 50%). + * times (0.1 s is 1.25%, 0.5 s is 6.25%, 1 s is 12.5%). */ .race { + /* What a colour means, as in the figures (figures/mock.css). */ + --server: var(--color-info-700); + --server-bg: var(--color-info-50); + --placeholder: var(--color-warning-700); + --placeholder-bg: var(--color-warning-50); + --hydrated: var(--color-success-700); + --hydrated-bg: var(--color-success-50); margin: 0; padding: var(--space-5); border: 1px solid var(--color-border); @@ -1206,48 +1213,78 @@ pre.mermaid[data-processed] svg { .race-part { position: relative; display: block; - height: var(--space-11); + height: var(--space-12); } .race-part--product { height: var(--space-16); } -/* A part's two faces, one over the other: its placeholder, then the part itself. */ -.race-loading, -.race-ready { +/* + * A part's faces, one over the other, each with its name and what it is: its + * placeholder, then its server HTML, then the same part hydrated. + */ +.race-face { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; - gap: var(--space-1-5); padding-inline: var(--space-2-5); + border: 1px solid; border-radius: var(--radius-base); + color: var(--color-text-heading); font-size: 0.75rem; line-height: 1rem; + font-weight: 500; overflow: hidden; } +/* The state, in words; the colour repeats it. */ +.race-face small { + font-family: var(--font-mono); + font-size: 0.6875rem; + font-weight: 400; +} + .race-loading { - border: 1px dashed var(--color-neutral-400); - color: var(--color-neutral-600); + border-style: dashed; + border-color: var(--placeholder); + background: var(--placeholder-bg); } -.race-ready { - border: 1px solid var(--color-primary-200); - background: var(--color-primary-50); - color: var(--color-primary-800); - font-weight: 500; +.race-loading small { + color: var(--placeholder); } -/* A line of text, drawn. */ -.race-ready i { - display: block; - width: 70%; - height: var(--space-1); +.race-html { + border-color: var(--server); + background: var(--server-bg); +} + +.race-html small { + color: var(--server); +} + +.race-hydrated { + border-color: var(--hydrated); + background: var(--hydrated-bg); +} + +.race-hydrated small { + color: var(--hydrated); +} + +/* Hydrated is the state the page is sent for: a dot marks it besides the colour. */ +.race-hydrated small::before { + content: ''; + display: inline-block; + width: var(--space-1-5); + height: var(--space-1-5); + margin-right: var(--space-1); border-radius: var(--radius-full); - background: var(--color-primary-200); + background: var(--hydrated); + vertical-align: 0.0625rem; } .race-blank { @@ -1308,89 +1345,177 @@ pre.mermaid[data-processed] svg { padding: var(--space-1) var(--space-3); } -.race-loading, -.race-ready, +.race-face, .race-blank, .race-elapsed { - animation-duration: 6s; + animation-duration: 8s; animation-timing-function: linear; animation-iteration-count: infinite; } +/* + * When each thing happens. A part lands as HTML (race-in-*) and is hydrated + * half a second later (race-live-*), with a ring that fades to mark the + * moment: the product at 0.1 s, the reviews at 1 s and the recommendations at + * 3 s when streamed, all of them at 3 s when sent whole. The reviews are the + * last part on the page, so the streamed page fills out of order. + */ .race-page--whole .race-blank { animation-name: race-until-3; } -.race-page--whole .race-ready, -.race-page--streamed .race-part--recommendations .race-ready { - animation-name: race-at-3; +.race-page--streamed .race-loading, +.race-page--streamed .race-part--product .race-html { + animation-name: race-in-0; } -.race-page--streamed .race-loading, -.race-page--streamed .race-part--product .race-ready { - animation-name: race-at-0; +.race-page--streamed .race-part--product .race-hydrated { + animation-name: race-live-0; +} + +.race-page--streamed .race-part--reviews .race-html { + animation-name: race-in-1; +} + +.race-page--streamed .race-part--reviews .race-hydrated { + animation-name: race-live-1; } -.race-page--streamed .race-part--reviews .race-ready { - animation-name: race-at-1; +.race-page--whole .race-html, +.race-page--streamed .race-part--recommendations .race-html { + animation-name: race-in-3; +} + +.race-page--whole .race-hydrated, +.race-page--streamed .race-part--recommendations .race-hydrated { + animation-name: race-live-3; } .race-elapsed { animation-name: race-clock; } -@keyframes race-at-0 { +@keyframes race-in-0 { 0%, - 1.6% { + 1.25% { opacity: 0; } - 3.5%, - 94% { + 3%, + 92% { opacity: 1; } - 98%, + 96%, 100% { opacity: 0; } } -@keyframes race-at-1 { +@keyframes race-live-0 { 0%, - 16.6% { + 7.5% { opacity: 0; + box-shadow: 0 0 0 0 var(--color-success-300); } - 18.6%, - 94% { + 9.25% { opacity: 1; + box-shadow: 0 0 0 var(--space-1) var(--color-success-200); } - 98%, + 15.5% { + box-shadow: 0 0 0 var(--space-1) transparent; + } + 92% { + opacity: 1; + } + 96%, 100% { opacity: 0; + box-shadow: 0 0 0 var(--space-1) transparent; } } -@keyframes race-at-3 { +@keyframes race-in-1 { 0%, - 50% { + 12.5% { + opacity: 0; + } + 14.25%, + 92% { + opacity: 1; + } + 96%, + 100% { + opacity: 0; + } +} + +@keyframes race-live-1 { + 0%, + 18.75% { + opacity: 0; + box-shadow: 0 0 0 0 var(--color-success-300); + } + 20.5% { + opacity: 1; + box-shadow: 0 0 0 var(--space-1) var(--color-success-200); + } + 26.75% { + box-shadow: 0 0 0 var(--space-1) transparent; + } + 92% { + opacity: 1; + } + 96%, + 100% { opacity: 0; + box-shadow: 0 0 0 var(--space-1) transparent; + } +} + +@keyframes race-in-3 { + 0%, + 37.5% { + opacity: 0; + } + 39.25%, + 92% { + opacity: 1; + } + 96%, + 100% { + opacity: 0; + } +} + +@keyframes race-live-3 { + 0%, + 43.75% { + opacity: 0; + box-shadow: 0 0 0 0 var(--color-success-300); + } + 45.5% { + opacity: 1; + box-shadow: 0 0 0 var(--space-1) var(--color-success-200); + } + 51.75% { + box-shadow: 0 0 0 var(--space-1) transparent; } - 52%, - 94% { + 92% { opacity: 1; } - 98%, + 96%, 100% { opacity: 0; + box-shadow: 0 0 0 var(--space-1) transparent; } } @keyframes race-until-3 { 0%, - 50% { + 37.5% { opacity: 1; } - 52%, - 98% { + 39.25%, + 96% { opacity: 0; } 100% { @@ -1403,10 +1528,10 @@ pre.mermaid[data-processed] svg { transform: scaleX(0); } 50%, - 94% { + 92% { transform: scaleX(1); } - 98%, + 96%, 100% { transform: scaleX(0); } @@ -1417,12 +1542,13 @@ pre.mermaid[data-processed] svg { } /* - * Reduced motion: the frame at 1.5 s, standing still. One page is blank, the - * other has its product and its reviews. Nothing moves, so there is nothing to pause. + * Reduced motion: the frame at 1.25 s, standing still. One page is blank; the + * other has its product hydrated, a placeholder for its recommendations and, + * below that, its reviews as HTML. Nothing moves, so there is nothing to pause. */ @media (prefers-reduced-motion: reduce) { .race * { - animation-delay: -1.5s; + animation-delay: -1.25s; animation-play-state: paused; }