Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c115f13
feat: Phase 1 - Terminal reconnection foundation
blink-so[bot] Jul 1, 2025
c10349b
fix: Improve useRetry hook logic
blink-so[bot] Jul 1, 2025
3f45b74
fix: Complete useRetry hook implementation and tests
blink-so[bot] Jul 1, 2025
834b2e5
style: Apply biome formatting fixes to useRetry hook
blink-so[bot] Jul 1, 2025
d398265
fix: Use window.setTimeout/setInterval for browser compatibility
blink-so[bot] Jul 1, 2025
dd7adda
refactor: consolidate useRetry state with useReducer
blink-so[bot] Jul 1, 2025
5766fc0
Reset TerminalPage files to main branch state
blink-so[bot] Jul 2, 2025
b1e453b
Add useWithRetry hook for simplified retry functionality
blink-so[bot] Jul 2, 2025
d4326fb
Clean up useWithRetry hook implementation
blink-so[bot] Jul 2, 2025
8323192
Remove useRetry hook and replace with useWithRetry
blink-so[bot] Jul 2, 2025
3022566
Refactor useWithRetry hook according to specifications
blink-so[bot] Jul 2, 2025
bde014c
Preserve attemptCount when max attempts reached
blink-so[bot] Jul 2, 2025
cb363db
Fix formatting
BrunoQuaresma Jul 2, 2025
55036a4
Fix hook and tests
BrunoQuaresma Jul 2, 2025
000f0e4
feat(hooks): remove max attempts limit from useWithRetry hook
BrunoQuaresma Jul 3, 2025
f9832c0
refactor(hooks): remove attemptCount from useWithRetry state and rena…
BrunoQuaresma Jul 3, 2025
4fd4885
fix(hooks): update useWithRetry tests for nextRetryAt API and add use…
BrunoQuaresma Jul 3, 2025
7b14acd
fix(hooks): prevent race condition in useWithRetry after unmount
BrunoQuaresma Jul 3, 2025
323f6ba
Fix formatting
BrunoQuaresma Jul 3, 2025
062bfa5
fix(hooks): prevent duplicate calls to useWithRetry while loading
BrunoQuaresma Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Preserve attemptCount when max attempts reached
- Do not reset attemptCount when no more attempts are possible
- Add attemptCount to UseWithRetryResult interface
- Return attemptCount in hook result for tracking
- Update tests to verify attemptCount preservation
- Add comprehensive test for attemptCount behavior

This allows consumers to track how many attempts were made,
even after all retry attempts have been exhausted.

Co-authored-by: BrunoQuaresma <3165839+BrunoQuaresma@users.noreply.github.com>
  • Loading branch information
blink-so[bot] and BrunoQuaresma committed Jul 2, 2025
commit bde014c401d85755d0a79927b0b256f2dff67ca8
37 changes: 37 additions & 0 deletions site/src/hooks/useWithRetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("useWithRetry", () => {

expect(result.current.isLoading).toBe(false);
expect(result.current.retryAt).toBe(null);
expect(result.current.attemptCount).toBe(0);
});

it("should execute function successfully on first attempt", async () => {
Expand All @@ -35,6 +36,7 @@ describe("useWithRetry", () => {
expect(mockFn).toHaveBeenCalledTimes(1);
expect(result.current.isLoading).toBe(false);
expect(result.current.retryAt).toBe(null);
expect(result.current.attemptCount).toBe(0);
});

it("should set isLoading to true during execution", async () => {
Expand Down Expand Up @@ -122,6 +124,7 @@ describe("useWithRetry", () => {
// After 10 attempts, should stop retrying
expect(result.current.isLoading).toBe(false);
expect(result.current.retryAt).toBe(null);
expect(result.current.attemptCount).toBe(10); // Should preserve final attempt count
});

it("should respect max delay of 10 minutes", async () => {
Expand Down Expand Up @@ -245,4 +248,38 @@ describe("useWithRetry", () => {
// Function should not have been called again
expect(mockFn).toHaveBeenCalledTimes(1);
});

it("should preserve attemptCount when max attempts reached", async () => {
mockFn.mockRejectedValue(new Error("Always fails"));

const { result } = renderHook(() => useWithRetry(mockFn));

// Start the call
await act(async () => {
await result.current.call();
});

expect(result.current.attemptCount).toBe(1);

// Fast-forward through 9 more retries to reach max attempts
for (let i = 1; i < 10; i++) {
const delay = Math.min(1000 * 2 ** (i - 1), 600000);
await act(async () => {
jest.advanceTimersByTime(delay);
});
expect(result.current.attemptCount).toBe(i + 1);
}

// After max attempts, attemptCount should be preserved
expect(result.current.attemptCount).toBe(10);
expect(result.current.isLoading).toBe(false);
expect(result.current.retryAt).toBe(null);

// Calling again should reset attemptCount
await act(async () => {
await result.current.call();
});

expect(result.current.attemptCount).toBe(1); // Reset on new call
});
});
6 changes: 4 additions & 2 deletions site/src/hooks/useWithRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface UseWithRetryResult {
call: () => Promise<void>;
retryAt: Date | null;
isLoading: boolean;
attemptCount: number;
}

interface RetryState {
Expand Down Expand Up @@ -63,8 +64,8 @@ export function useWithRetry(fn: () => Promise<void>): UseWithRetryResult {
executeAttempt(attempt + 1);
}, delay);
} else {
// No more attempts - reset state
setState({ isLoading: false, retryAt: null, attemptCount: 0 });
// No more attempts - keep attemptCount for tracking
setState(prev => ({ ...prev, isLoading: false, retryAt: null }));
}
}
};
Expand All @@ -83,5 +84,6 @@ export function useWithRetry(fn: () => Promise<void>): UseWithRetryResult {
call,
retryAt: state.retryAt,
isLoading: state.isLoading,
attemptCount: state.attemptCount,
};
}
Loading