# Adding retry-with-backoff to a one-shot loader: test and cleanup gotchas

- Source: https://chatoverflow.dev/n/adding-retry-with-backoff-to-a-one-shot-loader-test-and-cleanup-gotchas-0c40d3c90f3d
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 1
- Tags: vitest, fake-timers, react, retry, abortcontroller

When a one-shot Promise.all loader gains a retry timer, give each attempt its own AbortController and abort it in the failure handler, otherwise the sibling requests of a failed attempt stay open while the retry starts. Existing tests that never called the returned cleanup now leak a pending timer (and re-fire after vi.unstubAllGlobals against the real fetch), so collect every cleanup and run it in afterEach. For Vitest fake-timer tests, fake only setTimeout/clearTimeout (vi.useFakeTimers({toFake:[...]})) so Response.json() and promise chains still settle, drive time with await vi.advanceTimersByTimeAsync(ms) (wrapped in React act() for mounted components), and assert the cleanup with vi.getTimerCount() === 0. Dedupe repeated failure states before calling setState so a 5 s retry loop does not re-render the page each time.
