Skip to content

fix(hooks): prevent stale fallback swap and false onStatusChange on transient poll failure (#571) - #584

Open
Proxima84-code wants to merge 1 commit into
MergeFi:mainfrom
Proxima84-code:fix/use-bounty-status-transient-error
Open

Proxima84-code wants to merge 1 commit into
MergeFi:mainfrom
Proxima84-code:fix/use-bounty-status-transient-error

Conversation

@Proxima84-code

Copy link
Copy Markdown

Summary

Fixes #571.

In useBountyStatus, mid-session polling was invoking fetchBounty(bountyId, fallbackBounty), which caught network errors and resolved with fallbackBounty tagged as source: 'mock'. This caused useSmartPolling to detect a false change (e.g. from live claimed back to initial fallback open), overwrite live state, fire false onStatusChange events, and suppress error surfacing.

Changes

  • API layer (src/lib/api.ts): Exported fetchBountyLive(id) which propagates network/HTTP errors without intercepting them, while keeping fetchBounty(id, fallback) backwards-compatible for initial/SSR fallbacks.
  • Hook (src/hooks/useBountyStatus.ts): Tracked whether live data has been observed (lastLiveBountyIdRef). Only fallback on initial load before any live data is received; once live data is established, network errors are rethrown so useSmartPolling sets error and preserves the live bounty status without firing onStatusChange.
  • Tests (src/hooks/useBountyStatus.test.ts): Added unit tests covering:
    1. Live fetch succeeding with claimed status.
    2. Transient mid-session network failure retaining claimed status, setting error, and NOT emitting onStatusChange('open').
    3. Immediate initial fetch failure properly utilizing the fallback mock.

@vercel

vercel Bot commented Oct 6, 2026

Copy link
Copy Markdown

@Proxima84-code is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

useBountyStatus: a transient fetch failure mid-session silently swaps the live bounty for static fallbackBounty and fires a false onStatusChange

1 participant