App state in the URL
Search, filters, sort, selected type, view mode, and pagination page should live in the URL, and the app should parse the URL on load and render accordingly. Refresh then re-renders the page the user is on (together with "Stay logged in across page refresh", a reload returns you exactly where you were), and filtered views become shareable links — valuable for Model Bank.
Decided 2026-10-07 (Donnie):
- Hash params (e.g.
#/app?view=home&type=todo&q=x&sort-name&page=2=), not real query strings: a real path would require Hunchentoot to serveindex.htmlfor arbitrary paths (server-side catch-all, new deployment surface); hash survives refresh with zero server changes. - Encoded state: selected type, search terms, active filters, sort, pagination page. View mode is derived from the type's category, not encoded (decided 2026-10-16). Modals / lightbox excluded.
Implementation sketch:
- Small
urlState.ts(serialize / parse), no routing library — the frontend stays minimal and schema-driven. - Seed app state from the hash on mount; write via
history.pushStateon committed changes only (search writes on the debounce commit, not per keystroke);popstatelistener re-seeds so back / forward work. - Interplay with login: a shared URL opened while logged out parks the URL state, shows login, then restores it once auth completes.
Plan: app-state-url-plan.org (seven Grok passes + one Fable pass incorporated; view dropped from the format; form-dependent filter rows wait for the type's form — Step 2.5). Approved 2026-10-16; ready to implement.
Implemented 2026-10-16 per the plan, no deviations from its final rule set:
- New
web/src/urlState.ts:parseHash/canonicalize(behavioral absent-or-default contract, pass 7 — the single home of every omission rule incl. thehideExclusiveroles-only rule and filters values-array sort/dedupe),buildUrlState(raw mirror, never canonicalizes internally),urlStatesEqual(case-sensitive type compare, deep filters / bool),writeUrl(the only hash writer;pushStatebehind a canonical-to-canonical no-op compare,try=/=catch). Format#/app?hash params;viewnot encoded (derived from the type's category); unknown params ignored. App.tsxStep 2: writer effect mirroring the main fetch effect's deps exactly — one history entry per committed change; search writes on the debounce commit.- Step 2.5:
pendingFormRefetchRef+ a[data, type]arrival effect;fetchListbuilds the not-ilike / bool:eqrows only whendata'stype-keybelongs to the requested type and arms the one-shot refetch otherwise (a re-seeded first request no longer silently drops the filters or 404s on a stale field name).resetListQueryclears the ref. - Step 3: login seed in the
[loggedIn]effect — live-hash parse on every login transition, case-insensitive type validation againsttypes(unknown → landing flow +console.warn), full canonical assignment of every query field, timers cleared before the search pairs,defaultSortRefnulled, bool latch set only when the canonical entry carriesbool. - Step 4: history listener on
popstate+hashchange(one idempotent handler): equality gate first (both sides throughcanonicalize, type resolved throughtarget.name), then view derived from category,closeForm+ selection clear, full canonical assignment (neverchangeType— batched setters would fight the seed),defaultSortRefnulled, bool latchtarget ? target.name : typeon every applied entry. - Step 5 (parking/logout): no code needed, verified — the hash survives logout and logged-out screens write nothing (writer's
!loggedInguard); relogin re-seeds from the live hash. tsc+vite buildgreen (rannode_modules/.bindirectly; npm not on PATH on evo-x2). No backend changes, no test changes. Manual browser pass (plan Step 6's 22 cases) not yet run — needs a staging deploy.
- Slot
- 1800
- Status
- 60 Done
- Tags
- mvp, frontend, polish
- Contributors
- Donnie