Skip to content

Add exponential backoff and configurable max retries to useOptimisticData #178

Description

@Jagadeeshftw

📌 Description

useOptimisticData (src/shared/hooks/useOptimisticData.ts) retries failed fetches up to a hardcoded max of 5 at full speed with no backoff, and never exposes the retry count to callers. This can hammer a failing backend.

💡 Why it matters: Immediate full-speed retries can amplify outages and exhaust the API.

🧩 Requirements and context

  • Add exponential backoff (with jitter) between retries.
  • Make max retries and base delay configurable via options.
  • Expose retryCount/isRetrying from the hook.
  • Ensure aborts cancel scheduled backoff timers.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b feat/useoptimistic-backoff

2. Implement changes

  • Write/modify the relevant source: src/shared/hooks/useOptimisticData.ts
  • Write comprehensive tests: src/shared/hooks/useOptimisticData.test.ts
  • Add documentation: TSDoc @example
  • Include TSDoc doc comments
  • Validate security assumptions: timers cleared on unmount/abort

3. Test and commit

  • Run tests:
npm run test
  • Cover edge cases: backoff timing (fake timers), abort during backoff, custom max
  • Include test output and security notes in the PR description.

Example commit message

feat(hooks): exponential backoff + configurable retries in useOptimisticData

✅ Acceptance criteria

  • Retries use exponential backoff with jitter
  • Max retries/base delay configurable
  • retryCount exposed
  • Timers cleared on abort/unmount; tests assert timing

🔒 Security notes

Avoid retry storms; ensure backoff timers are always cleaned up.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial CampaignGrantFox official campaign issueenhancementNew feature or requestfrontendFrontend / UI workperformancePerformance / gas / resource use

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions