Loading, empty, error — a cockpit's real states
By the end of this lesson you will have every panel resolving its own five states, a sentence for each kind of failure, an error boundary around each panel so one crash leaves the rest standing, and a test per state that renders it from a literal fixture.
One panel failing must not take down the page. That sentence is easy to agree with and requires specific work.
Per panel, not per page
A page-level spinner means the slowest panel decides when anything appears, and a page-level error means one bad symbol blanks the cockpit. Both are wrong for a surface with independent parts.
Each panel resolves its own state, and there are five, not two:
- Loading — first fetch, no data yet. A skeleton the shape of the content, not a spinner.
- Refreshing — has data, fetching newer. Keep showing the old data with a subtle marker. Blanking a panel to show a spinner over data you already have is the single most common dashboard mistake.
- Ready — data, with its age.
- Empty — the request succeeded and there is nothing. Say why: no symbols added, no rows matched.
- Failed — say what failed and offer retry for that panel alone.
The distinction between loading and refreshing is where a cockpit feels calm or feels frantic, and it is one boolean.
Errors have kinds, and each needs different words
From what you have measured across three courses:
- 404, plain text
Ticker Not Found.— the person typed something wrong. Name the symbol. Backtest Strategies met this one; note it is not JSON, sores.json()throws. - 402 — out of calls for today. This is the one people mislabel as "something went wrong", and it is the most important to get right because it is the wall arriving. Say "you are out of API calls for today, they reset at 00:00 UTC" and show the meter. More calls today will not help.
- 429 — too many requests this minute (it counts requests, not calls). It clears by itself within a minute and the response says when (
Retry-After): wait, then retry. Different from 402 and needs different words. - 403 — the plan does not cover this data. Waiting will not help either; only a different plan does.
- 5xx or a timeout — upstream. Retry is reasonable here.
Five kinds, five messages. A generic error message across all five is a tool that cannot tell you what to do next.
An error boundary per panel
Even with every state handled, a render bug in one panel should not blank the cockpit. Wrap each panel in a boundary that shows "this panel crashed" with a reset, and keep the rest of the page alive.
This matters more here than anywhere else in the track, because panels are the part you will keep adding. A cockpit where a new panel can take down the whole page is a cockpit you stop extending.
Degrade rather than disappear
When data is stale and cannot refresh, show it stale and label it. Do not hide it, and do not show it silently as if it were current.
That is the honest behaviour, and it is also the behaviour that makes the wall in unit 4 visible instead of confusing. A person who sees "AAPL 309.90 · 47 min old · refresh unavailable" understands their situation. A person who sees a blank panel thinks the tool is broken.
Try it now
Force all five states by hand: empty your watchlist, request a nonsense ticker, throttle the network, and throw inside a panel's render on purpose. Screenshot each. That set of five screenshots is the honest picture of your cockpit, and most dashboards have never had it taken. Then ask your agent to turn each state into a test that renders the panel from a literal fixture, so the five states stay handled after the next change.
The prompt
Mock mode on, plan mode on, and paste:
Plan, then build, panel states. In src/lib/panel-state.ts derive one of
loading, refreshing, ready, empty or failed from what a panel holds: its
rows, whether a fetch is running, and its last failure. Refreshing keeps
the old rows on screen with a marker and never blanks them; a failure
keeps them too, labelled with their age. Give each failure kind in
src/lib/failure.ts its own sentence, what happened and what to do next:
404, a symbol that does not exist (name it); 402, out of calls for
today (they reset at 00:00 UTC, and retrying will not help); 429, too
many requests this minute (wait for Retry-After, then retry); 403, data
this plan does not cover; 5xx or a timeout, trouble upstream (retry).
Give the cockpit a Refresh button that asks the market store again, so
refreshing is something you can press. A panel with no symbols says it
has none; a panel whose request came back with nothing says that
instead. Wrap every panel in src/components/PanelBoundary.tsx, which
shows that the panel crashed, offers a reset, and leaves the others
drawing. Write
tests/panel-state.test.ts first: one test per state, each from a literal
fixture, and one per failure kind. Mock mode; Refresh only repeats the request the cockpit already makes. Run npm
test, typecheck, lint and check:leak, and show me the diff.
A good answer adds the state module, the boundary and the test, changes src/lib/failure.ts, and changes how the container draws each panel. No panel grows a spinner of its own.
Check it yourself
- Since the last lesson the watchlist panel's symbols come from your saved layout, so emptying
src/lib/watchlist.tschanges nothing. Ask the agent to save a layout namedemptyin the store, a copy of the one you have open with the watchlist panel's symbols removed, and openlocalhost:3000/dashboard?layout=empty: the watchlist panel says it has no symbols rather than showing nothing. Switch back to your own layout. - Add a ticker that does not exist: its row is marked unavailable by name, and the other rows keep their prices.
- Throttle the network in the browser's developer tools and press the cockpit's Refresh button: the old rows stay, with a marker that they are refreshing. (The browser's own reload button starts the page over, so there are no old rows to keep.) If the answer comes back at once, the browser served it from its own cache, which the proxy allows for a minute: wait a minute and press Refresh again.
- Ask the agent to put
throw new Error("test")at the top of the quote panel's component and reload: that panel says it crashed and offers a reset, and the rest of the cockpit still draws. Ask the agent to remove the throw. npm testlists a test for each of the five states.
Compare with ours
// src/lib/panel-state.ts: five states, and refreshing never blanks what you have
export function panelState(p: { rows: Row[] | null; fetching: boolean; failure: Failure | null }) {
if (p.failure) return { kind: "failed", failure: p.failure, rows: p.rows } as const; // old rows stay, labelled
if (p.rows === null) return { kind: "loading" } as const; // a skeleton, not a spinner
if (p.fetching) return { kind: "refreshing", rows: p.rows } as const;
if (p.rows.length === 0) return { kind: "empty" } as const; // and say why
return { kind: "ready", rows: p.rows } as const; // with its age
}
The full state at the end of this unit is on the starter's branch ref/build-a-dashboard/u2.

Checkpoint
npm test && npm run typecheck
git status # the files you expect, and no .env file
git add -A
git commit -m "Five panel states, a sentence per failure kind, a boundary per panel"
Then answer this lesson's questions.