Skip to content

fix(hooks): reset loading state to false on successful execution in useRetry (#4) - #110

Open
dwaddle wants to merge 1 commit into
StellarSend:mainfrom
dwaddle:fix/useretry-loading-state-reset
Open

dwaddle wants to merge 1 commit into
StellarSend:mainfrom
dwaddle:fix/useretry-loading-state-reset

Conversation

@dwaddle

@dwaddle dwaddle commented Sep 15, 2026

Copy link
Copy Markdown

Fixes #4

Summary

Resolves a control-flow bug in src/hooks/useRetry.ts where run() early returns upon successful execution inside the retry loop, skipping the trailing setLoading(false) statement and leaving components with stuck loading: true state.

Key Changes

• useRetry Control Flow (src/hooks/useRetry.ts):

  • Wrapped the execution loop in a top-level try { ... } finally { setLoading(false); } block to guarantee loading state is reset to false regardless of whether run() returns early after a successful call or finishes after exhausting retries.
    • Unit Test Suite (src/hooks/useRetry.test.ts):
  • Added unit test suite covering:
    • loading resets to false on immediate success.
    • loading resets to false on success after transient retry.
    • loading resets to false and sets error message when all retries are exhausted.

Quality Verification

  • npx vitest run src/hooks/: 29/29 tests passing across all hook test suites (100% pass rate).
  • git diff --check: 0 formatting / whitespace errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useRetry hook leaves loading stuck true after a successful retry

1 participant