refactoring-backend #3

Merged
lukas.pupkalipinski merged 403 commits from refactoring-backend into main 2026-05-20 20:23:46 +02:00
Showing only changes of commit 57ee5a2892 - Show all commits

View File

@@ -1,38 +1,3 @@
### TASK-ABORT-01 — Missing `signal` Parameter on Multiple API Functions
**Where found**
The following API functions accept no `signal` parameter and therefore cannot be cancelled regardless of what the calling hook does:
| File | Function |
|------|----------|
| `frontend/src/api/history.ts` | `fetchHistory`, `fetchIpHistory` |
| `frontend/src/api/map.ts` | `fetchBansByCountry` |
| `frontend/src/api/jails.ts` | `fetchActiveBans`, `fetchJails` |
| `frontend/src/api/config.ts` | `fetchJailConfig`, `fetchInactiveJails`, `fetchJailConfigFiles`, `fetchFilterFiles` (partially — calls `fetchFilters` which accepts signal but discards it), `fetchActionFiles`, `fetchFilterFile`, `fetchActionFile` |
| `frontend/src/api/blocklist.ts` | `fetchImportLog`, `previewBlocklist` |
**Goal**
Add an optional `signal?: AbortSignal` parameter to each function and forward it to the underlying `get()` call. Example:
```ts
export async function fetchHistory(query: HistoryQuery, signal?: AbortSignal): Promise<HistoryResponse> {
return get<HistoryResponse>(`${ENDPOINTS.history}?${buildQuery(query)}`, signal);
}
```
Then update every calling hook to forward its controller's signal.
**Possible traps and issues**
- `fetchFilterFiles` is an adapter that calls `fetchFilters()` internally. The correct fix is to accept `signal` and thread it into `fetchFilters(signal)`, then map the result.
- `previewBlocklist` is called from `useBlocklists.previewSource` which has no abort machinery. That hook should also be updated to add an `AbortController` if unmount cancellation is desired.
- Search for all call sites after adding the parameter; TypeScript's optional `?` means existing callers will not break but they should be updated to pass the signal where available.
**Docs changes needed**
Add a coding convention to `Docs/Web-Development.md`: "All API functions that perform a `GET` request must accept an optional `signal?: AbortSignal` parameter and forward it to the HTTP client."
**Why this is needed**
Without signals, navigating away from a page mid-fetch does not cancel the in-flight HTTP request. The response arrives, the callback fires, and React attempts a state update on an unmounted component. In development mode React warns about this; in production it causes silent no-ops and wastes server resources.
---
### TASK-ABORT-02 — Hooks Create `AbortController` but Never Forward Signal to API
**Where found**