Skip to content

feat(ui): migrate the stats poll to React Query (W5.2b) - #432

Merged
krisarmstrong merged 1 commit into
mainfrom
feat/stem-react-query-stats
Jun 15, 2026
Merged

feat(ui): migrate the stats poll to React Query (W5.2b)#432
krisarmstrong merged 1 commit into
mainfrom
feat/stem-react-query-stats

Conversation

@krisarmstrong

Copy link
Copy Markdown
Collaborator

What

Stage 2b of the App.tsx decomposition (follows #431). Replaces the manual 1s setInterval stats poll with useQuery.

Removed: statsIntervalRef, the fetchStats useCallback, and the connected-gated polling effect (incl. the expireSession interval cleanup).

useQuery({ queryKey: ['stats'], enabled: connected, refetchInterval: 1000,
           refetchIntervalInBackground: true, staleTime: 0, retry: false, queryFn })

Behavior-preserving

  • Cadence: refetchInterval: 1000 + refetchIntervalInBackground: true matches the old setInterval (which polled regardless of tab visibility); enabled: connected replicates start/stop on connection; staleTime: 0 keeps every tick fresh.
  • Test-status state machine: handleStatusTransition (→ fetch result on completion / clear on start) now runs as a useEffect keyed on the query data — fires once per poll, exactly as fetchStats did.
  • Reset on logout: queryClient.clear() (added in feat(ui): add React Query + migrate the interfaces read (W5.2a) #431) leaves the query dataless, so stats falls back to initialStats — the explicit reset is gone.
  • useTestProgress/expectedDuration moved below the query (they read stats).

Impact

App.tsx useState 26 → 24 (stats + interfaces now query-owned); −38 net lines this slice.

Verification

tsc + biome clean · npm run build green · 183/183 unit tests. The live polling + test-status transitions are exercised by the fullstack E2E on this PR.

Stage 2b of the App.tsx decomposition. Replaces the manual 1s setInterval
stats poll (statsIntervalRef + fetchStats useCallback + the connected-gated
polling effect) with a useQuery:
- enabled: connected, refetchInterval: 1000, refetchIntervalInBackground:
  true (matches the old setInterval running regardless of tab visibility),
  staleTime: 0, retry: false.
- The test-status state machine (handleStatusTransition → fetchTestResult /
  clear-on-start) now runs as a useEffect keyed on the query data, firing once
  per poll exactly as before.
- statsIntervalRef removed (incl. its expireSession cleanup); the stats query
  disables when connected flips false. handleLogout's explicit stats reset is
  gone — queryClient.clear() (added for the cross-session fix) leaves the
  query dataless, so stats falls back to initialStats.
- useTestProgress/expectedDuration moved below the query (they read stats).

App.tsx useState 26 → 24 across W5.1/2a/2b. tsc + biome clean; build green;
183/183 unit tests pass. Live polling/test-status behavior is covered by the
fullstack E2E on the PR.
@krisarmstrong
krisarmstrong enabled auto-merge (squash) June 15, 2026 15:46
@github-actions

Copy link
Copy Markdown
Contributor

License Compliance Report

All dependencies pass license compliance checks

Go Dependencies

  • Unknown: 31 package(s)
  • MIT: 26 package(s)
  • BSD-3-Clause: 16 package(s)
  • Apache-2.0: 11 package(s)
  • BSD-2-Clause: 1 package(s)

npm Dependencies

See full report in workflow artifacts

Allowed Licenses: MIT, Apache-2.0, BSD-*, ISC, CC0-1.0, MPL-2.0
Forbidden: GPL, AGPL, SSPL (strong copyleft)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant