fix(nav): move AbortController creation synchronously in render

Previously the AbortController was created inside useEffect, which runs
after render. This meant requests initiated during render received
the previous cycle's (possibly aborted) signal and were cancelled
immediately instead of completing.

Now the controller is created synchronously when pathname changes, before
any request can be initiated on the new route. The old controller is
aborted in the same conditional block, before the new one is created.

Side effect: removed resolved Issue #49 from Tasks.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-05-03 22:37:07 +02:00
parent 7fcfc14199
commit 3376009903
2 changed files with 25 additions and 39 deletions

View File

@@ -1,32 +1,3 @@
### Issue #49: HIGH - Dual Auth Error Handlers With No Deduplication Guard
**Where found**:
- `frontend/src/providers/AuthProvider.tsx:50-56`
- `frontend/src/api/client.ts:143` `setUnauthorizedHandler`
- `frontend/src/utils/fetchError.ts` `setAuthErrorHandler`
**Why this is needed**:
Both handlers fire independently on a 401. Without a deduplication guard, logout logic executes twice, causing a React state mutation race and potentially double-navigating to the login page.
**Goal**:
Ensure auth error handling fires exactly once per 401 response.
**What to do**:
1. Introduce a module-level `isLoggingOut` flag (or use a ref) that is set before the first logout dispatch and checked before the second.
2. Alternatively, consolidate into a single handler and remove one registration.
**Possible traps and issues**:
- The "defense-in-depth" rationale for two handlers may be intentional; confirm with team before removing one.
- The flag must be reset after the login page is reached.
**Docs changes needed**:
- Add comment in `AuthProvider.tsx` explaining the deduplication guard.
**Doc references**:
- `frontend/src/providers/AuthProvider.tsx` inline comment about cross-tab logout
---
### Issue #50: HIGH - Navigation Abort Signal Timing Bug
**Where found**: