Commit 598a802
authored
## Root cause
`useIdempotentAction`'s `useEffect` cleanup only set `isMountedRef.current = false`. The `inFlightActions` ref (`Map<string, Promise<unknown>>`) was **never cleared on unmount**.
Any Promise stored in that Map — together with the closures it captured (state setters, `isProcessingRef`, `lastExecutionTime`, etc.) — was retained in memory until the Promise settled. On high-churn routes where the hook's component mounts and unmounts frequently, these retained closures accumulate and prevent GC of the entire component subtree.
## Fix (`src/hooks/useIdempotentAction.ts`)
Added `inFlightActions.current.clear()` to the `useEffect` cleanup so in-flight Promise references are released the moment the component unmounts, allowing the GC to reclaim them.
```diff
return () => {
isMountedRef.current = false;
+ inFlightActions.current.clear();
};
```
## Regression test (`src/hooks/__tests__/useIdempotentAction.test.ts`)
New test `"regression: clears inFlightActions on unmount …"`:
1. Starts an action, leaving a Promise in `inFlightActions`.
2. Unmounts the component while the Promise is in flight.
3. Resolves the Promise after unmount — verifies no stale-state update throws.
4. Confirms a fresh hook instance executes normally, proving no lingering state.
Closes #1221
Closes #1220
1 parent d74ca75 commit 598a802
2 files changed
Lines changed: 52 additions & 0 deletions
File tree
- Dechat/dex_with_fiat_frontend/src/hooks
- __tests__
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
353 | 402 | | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
0 commit comments