Fix/use async initial state refetch#326
Merged
Jagadeeshftw merged 5 commits intoJul 23, 2026
Merged
Conversation
…d with ready initialState
# Conflicts: # src/components/SettlementTable.test.tsx # src/components/SettlementTable.tsx # src/components/SettlementsPanel.test.tsx
Retry logic in apiRequest/apiTextRequest called isAbortError(err) on every retry-eligible failure, but the function didn't exist anywhere in the module -- a pre-existing bug on main that threw a ReferenceError instead of checking abort status.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #266
Fixes an issue where
useAsyncalways executed its initial fetch effect on mount, even when seeded with{ status: "ready", data: ... }initialState.In detail pages such as
AnchorDetail(/anchors/[id]) andSettlementDetail(/settlements/[id]), passing server-fetchedinitialDataintouseAsyncpreviously triggered an immediate redundant client-side re-fetch of the exact same anchor or settlement immediately after rendering.This PR updates
useAsyncto skip callingloadduring mount whennonce === 0andinitialState.status === "ready". Subsequent explicit re-fetches viareload()orrefresh()continue to trigger re-fetches as expected.Changes Made
src/hooks/useAsync.ts: Added an early return condition to theuseEffectwhennonce === 0 && initialState.status === "ready". Updated JSDoc documentation.src/hooks/useAsync.test.ts: Added unit tests asserting:loadis skipped on mount when initialized withstatus: "ready".reload()orrefresh()after initialization with"ready"state triggersload.src/components/AnchorDetail.test.tsx: Added unit tests verifyinginitialDataskipsfetchAnchoron mount and re-fetches on deactivation reload.src/components/SettlementDetail.test.tsx: Added unit tests verifyinginitialDataskipsfetchSettlementon mount and re-fetches on execution refresh.Verification
useAsync.test.ts,AnchorDetail.test.tsx, andSettlementDetail.test.tsx.npx tsc --noEmit.