Cancel an in-flight Recent updates read when the sheet closes
CI / ci (push) Successful in 9m24s
CI / ci (pull_request) Successful in 9m0s

The updates query now passes TanStack Query's abort signal to apiFetch, so
closing the sheet while its read is pending aborts that GET. An immediate
reopen then sends its own read instead of adopting the one sent before a
newer event was stored, and marks seen only what that read returned.

Closes MQ-176-01 (task 96e2dc3f-1f8a-4114-bcb5-e0f93c349165).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 15:07:37 -04:00
co-authored by Claude Opus 5.5
parent 6956f6f049
commit d9b63bd08c
2 changed files with 56 additions and 3 deletions
+5 -3
View File
@@ -146,13 +146,15 @@ export function parseUpdates(where: string, body: unknown, origin: string): Upda
// useUpdates is the Recent updates (GET /api/v1/updates): the last ten
// notification events, newest first. Each opening of the sheet reads it
// afresh (refetchOnMount 'always'), whatever the query client still holds;
// the sheet shows, and marks seen, only the list that opening read.
// the sheet shows, and marks seen, only the list that opening read. Closing
// the sheet aborts a read still in flight, so a reopen sends its own rather
// than adopt one sent before it.
export function useUpdates() {
const { apiFetch } = useApi()
return useQuery({
queryKey: UPDATES_KEY,
queryFn: async () =>
parseUpdates(`GET ${UPDATES_PATH}`, await apiFetch<unknown>(UPDATES_PATH), window.location.origin),
queryFn: async ({ signal }) =>
parseUpdates(`GET ${UPDATES_PATH}`, await apiFetch<unknown>(UPDATES_PATH, { signal }), window.location.origin),
refetchOnMount: 'always',
})
}