0056. Live refresh of the game pages, and a dev-only account link
Source:
docs/decisions/0056-live-refresh-and-dev-account-link.md. Generated at build time; edit the source file.
Date: 2026-11-22. Status: accepted (M5a Task 12). Builds on 0046 (read model and access) and ADR-WEB-8 (event delivery). The plan named this record 0055, which Task 8 had already taken.
Context
Section titled “Context”The overview and the games explorer are server components that read the database directly (0046, R2). While the worker analyses a player’s games, the stream (ADR-WEB-8, M4 T22/T23) tells the browser game.analysed, and M4 T23’s applyEvent invalidates the TanStack Query key games(accountId). The pages hold no TanStack data of their own, so something has to turn that invalidation into a fresh server render.
Separately, the owner already has 500 analysed games imported by the worker, but the chess.com location-code flow (M4 T19/T21) is the only way to link them to a signed-in user, and the owner wants to open their games now.
Decision
Section titled “Decision”- An observer plus
router.refresh().LiveRefresh({ accountIds })mounts oneuseQueriesobserver pergames(accountId), withstaleTime: Infinityand aqueryFnthat returnsDate.now(). It holds no game data; it only gives the stream’s invalidation a live query to land on. It watches the query cache for aninvalidateon exactly those keys and then callsrouter.refresh(). Server components stay the single read path: no API route, no client copy of the read model, no second source of truth to keep consistent. - Throttled to one refresh per 3000 ms, with a trailing call. The first invalidation refreshes at once; any more inside the window collapse into one trailing refresh at the window’s end, so a burst of 50 analysed games costs at most one refresh every 3 s and the last game is never missed. Unmounting drops a pending trailing refresh.
staleTime: Infinitymeans focus and reconnect never refetch, so only an invalidation refreshes. - Mounted on
/appand/app/gameswith the user’s scoped account ids (scopedAccountIds). The review page is a single finished game and does not refresh under the reader. src/lib/query-keys.tslands here, with exactly T23’s specified shape, because T23 has not merged yet. Until T23 (stream hook) and T27 (provider wiring) land, nothing invalidates these keys in the running app, soLiveRefreshis inert but harmless.- The front door picks the page.
/sends a signed-in user with at least one link to/app, one with none to/app/accounts, and a signed-out visitor to/sign-in. The magic-link and socialcallbackURLand the signed-in/sign-inredirect point at/, so a returning player lands on their overview. New users still go to/welcome/age, then Accounts. dev:linkfor local development only.pnpm --filter @ci/web dev:link --email <e> --platform chesscom --username <name>(scripts/dev-link-account.ts, run through tsx with thedevelopmentexport condition so it needs no package build):- refuses with “dev:link is for local development only” when
NODE_ENVisproductionor when the database is not local. The host is judged as the driver connects, not as WHATWGURLreads it (review fix round 1): postgres.js honours?host=, splits the userinfo at the last@and does not end the authority at#. So any URL with ahostorhostaddrparameter, a fragment, or more than one@is refused outright (that also covers unix-socket paths such as?host=/cloudsql/…); then the WHATWG host and every host postgres.js itself parses (postgres(url).options.host, which opens nothing) must be exactlypostgres,localhostor127.0.0.1, never a prefix or suffix match. An unparsable URL is refused. The CLI checks all this before opening a connection; - after connecting, and before any read or write, it also asks the server for
inet_server_addr()and refuses unless that is a unix socket (null), loopback, or a private address (10/8, 172.16/12, 192.168/16, fc00::/7), which is where the compose service lives; - needs a user who has signed in once and an account the worker has already imported, and says which is missing;
- inserts one
account_linksrow with methodusernameandverified_atnull, doing nothing when it exists, and writes nothing else. It never imports and never touchesgames,linked_accountsor any other table.
- refuses with “dev:link is for local development only” when
The link makes no ownership claim
Section titled “The link makes no ownership claim”The row is unverified. It is the same kind of link a user gets by typing a chess.com username before verifying (0046, R1: chess.com games are public, and an unverified link is labelled “Unverified” on the overview). Proving ownership stays with the location-code flow (M4 T19/T21), which upgrades the link to verified. Nothing here sets verified_at, linked_accounts.user_id or linked_accounts.verified_at.
Consequences
Section titled “Consequences”- A refresh re-renders the whole server page, which costs a few database reads per window; the 3 s throttle bounds that.
- A second store of query keys exists until T23 merges; T23 must reuse this file, not add another.
- The dev script is safe to keep in the repo: production and remote databases are refused, and it only ever adds an unverified link.