fix(api): add AbortController support to ApiClient - #399
Merged
DeFiVC merged 2 commits intoAug 30, 2026
Merged
Conversation
❌ Deploy Preview for chainlearn failed.
|
|
@Ayomide3271 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Overview
This PR adds AbortController support to the ApiClient so in-flight requests can be cancelled. When a component unmounts mid-request, the controller's signal aborts the fetch, which prevents memory leaks and state updates on unmounted components.
Related Issue
Closes #300
Changes
ApiClient
src/lib/api/client.tssignalparameter toget/post/put/deleteand threads it throughfetchWithRetrytofetch.AbortErrorso callers can detect them and skip state updates. Internal timeouts keep their existing retry behavior.isAbortError()helper so consumers can reliably detect cancelled requests (aDOMException, which is not aninstanceof Error).src/lib/api/client.test.tsAPI wrappers
src/lib/api/{auth,courses,credentials,notifications,quizzes,rewards}.ts— accept and forward an optionalAbortSignal(additive, non-breaking).Data-fetching hooks
src/lib/hooks/{use-courses,use-credentials,use-notifications,use-quiz,use-rewards}.ts— create anAbortControllerper request, abort it inuseEffectcleanup on unmount, and skip state updates when the request was aborted.Verification Results
signalparameter on every ApiClient method, forwarded tofetchAbortError; aborted requests never touch the error storesetStatewhenisAbortError(err)is true