Skip to main content

0017 — Portal view state in the address

Status: Accepted · Date: 2026-11-19

Context​

Every portal list page kept its search, filters, sort and page in local React state. A reload, a trip to another page and back, or a shared link all lost them, so a coach re-typed the same History search after every detour. Two pages had already solved this on their own: Profiles kept its athlete × exercise pairing in the query (use-matrix-selection.ts), and the Live Hub keeps its screen there (use-hub-route.ts). Other pages read one-shot deep links (?athlete=, ?tag=) and never wrote back.

The options were the URL query, sessionStorage, and an in-memory store per page. Only the query survives a reload and travels with a copied link, and it is what the browser's Back button already restores.

Decision​

  1. A page's view lives in the URL query. Search text, filter facets, toggles, sort, table page, tab and shown period. Selections, open drawers, dialogs and per-browser preferences stay out.
  2. Written in place. Changes go through history.replaceState (debounced), not router.push: filtering creates no history entries, and Back leaves the page.
  3. Read once, on mount, through useSearchParams. The page seeds ordinary React state from it; window.location can still hold the previous address during a link's transition.
  4. One shared module and one codec per page. apps/portal/src/app/dashboard/url-state.ts holds the hooks and tolerant readers; each page has a pure, tested <page>-view.ts. Defaults write nothing, so a page at its defaults has a clean address, and the key names are the same on every page (see Routing).
  5. No sidebar memory. The sidebar opens a page at its defaults; whether it should reopen the last view is a separate product question.

Consequences​

  • Reload, Back and shared links show the same view on every list page.
  • Athlete and tag names appear in the address and the browser's history, as the existing ?athlete= deep link already did.
  • A link to the page that is already open does not re-seed it (read once).
  • DataTable gained a controlled pageState prop; the dashboard layout wraps pages in a Suspense boundary for useSearchParams.
  • No new dependency: the hooks are a thin layer over useSearchParams and the History API instead of a library such as nuqs.