app/ # One file per aggregate (pools.ts, reservations.ts, …) = TanStack Query hooks. queryKeys.ts is the single key registry. (mutations/ and queries/ dirs exist but are empty.)
Changes for docs/20260807_1255_activity_page_staleness_fixes.md: 88 added lines, 0 removed lines.
Original line number
Diff line number
Diff line
# Activity page — stale and misleading reads
## What & why
Reported symptom: `/activity` "seems cached and sometimes displays wrong information."
It was four independent defects stacked, not one cache bug. Reservations advance
`CREATED → PROVISIONING → ACTIVE → RELEASING → RELEASED` on the **server** — by scheduler, by
an external orchestrator, or by another operator's lifecycle signal — with nothing happening in
the operator's tab to trigger a refetch. Every layer of this page assumed the opposite.
| # | Defect | Where | Effect |
|---|---|---|---|
| 1 | No refresh mechanism at all | `app/queryClient.ts:28-30` — `staleTime: 30_000`, `refetchInterval: false`, `refetchOnWindowFocus: false` | Rows were only ever as fresh as the moment they were first fetched. No poll, no focus refetch, no Refresh button. |
| 2 | Background refetches were invisible | `ActivityPage.tsx` read `isPending` | In Query v5 `isPending` is only true with **no** cached data. A background refetch is `isFetching`, so the table kept rendering old rows, with no indication, until new data landed. Re-entering within `staleTime` refetched nothing at all. |
| 3 | A failed fetch rendered as an empty result | `ActivityPage.tsx` passed `loading`/`empty` to `StateView` but not `error` | Failure → `data` undefined → `empty` true → *"No reservations match the current filters."* Above it, `{String(error)}` on a `ProblemDetail` object rendered the literal text `[object Object]`. |
| 4 | Every mount fired a request the server cannot answer | the off-screen view was parked on `{ page: 0, size: 0, to: DateTime.fromMillis(0) }` with no `enabled` flag | `size=0` is what Spring's `PageRequest.of(0, 0)` rejects. |
Defect 3 is the one that most literally matches "displays wrong information": a broken backend
read as "nothing is booked".
**Refresh policy chosen (by the user): poll while visible.** 15s on the activity list, plus
`refetchOnWindowFocus`, both scoped to these queries rather than changing the global defaults.
Polling pauses while the tab is in the background (`refetchIntervalInBackground: false`).
### Two things that looked like causes and were not
-**Mutation invalidation is correct.**`queryKeys.activity.all()` is `['activity']`, a prefix of
both `activity.list(params)` and `activity.detail(id)`, so the existing `invalidateQueries`
calls do cover the list and the detail page.
-**`buildActivityParams` silently drops `membershipId` and `correlationId`** (`ActivityListInput`
in `mappers/pagination.ts` never declared them) — but it is **dead code**. Only its own test
imports it; `activityGateway.ts:23-38` builds its own params and forwards both correctly. Left
alone here; worth deleting or reconciling separately.
## Changes
**`src/app/activity.ts`**
-`useReservations(q, options?)` gains a `ReservationListOptions` bag — `refetchInterval`
(default `false`) and `enabled` (default `true`). Callers opt in; the global defaults are
untouched for every other query in the app.
- On that query: `refetchIntervalInBackground: false`, and `refetchOnWindowFocus: true` +
`staleTime: 0` overriding the global `false`/`30_000`.
-`useReservation(id)` gets the same `refetchOnWindowFocus` + `staleTime: 0`. The detail page
picks which lifecycle signals to offer from `lifecycleState`, so a cached read there does not
just look wrong — it offers the wrong actions.
**`src/features/activity/ActivityPage.tsx`**
-`ACTIVITY_POLL_MS = 15_000`; the displayed view polls, the off-screen one is `enabled: false`
against an inert placeholder key (`INERT_QUERY`) instead of throwaway params. Both hooks stay
mounted so hook order is stable.
- Destructures `isFetching` and `dataUpdatedAt`; `refreshing = isFetching && !isPending` drives a
16px spinner, and an "Updated HH:mm:ss" caption sits beside the view toggle. The caption is
suppressed until the first response (`dataUpdatedAt > 0`) so the page never claims a freshness
it does not have.
-`error` now flows into `StateView` (which already renders `ProblemDetailAlert` — the `FlagsTab`
in the same file was already doing this); the calendar branch renders `ProblemDetailAlert`
directly. The `{String(error)}` alert is gone, as is the now-unused `Alert` import.