Skip to content

Commit a59bcad

Browse files
committed
fix: auto retry loop
1 parent b1216b3 commit a59bcad

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

usecases/lib/hooks/useAutoRetry.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useMockApi } from '~usecases/lib/components/mocks/MockApiProvider';
77
import { selectAllFailedTransitions } from '~usecases/lib/store/epics/selectors';
88

99
/** Retries all failed transitions when coming back online.
10+
* Only fires on the offline → online transition, not while already online.
1011
* The `retry` callback is pattern-specific:
1112
* - Basic/Thunks: routes each action to the correct handler/thunk
1213
* - Sagas: re-dispatches the stage action (saga watcher picks it up) */
@@ -16,7 +17,12 @@ export const useAutoRetry = (retry: (action: StagedAction) => void) => {
1617
const retryRef = useRef(retry);
1718
retryRef.current = retry;
1819

20+
const wasOnline = useRef(online);
21+
1922
useEffect(() => {
20-
if (online) failedTransitions.forEach((a) => retryRef.current(a));
23+
if (online && !wasOnline.current) {
24+
failedTransitions.forEach((a) => retryRef.current(a));
25+
}
26+
wasOnline.current = online;
2127
}, [online, failedTransitions]);
2228
};

0 commit comments

Comments
 (0)