Repository navigation
fix(download): don't report a canceled or replaced download through onError - #1057
Draft
staszekscp wants to merge 1 commit into
Draft
staszekscp wants to merge 1 commit into
staszekscp wants to merge 1 commit into
Conversation
…nError When the source changes while a download is running, the old download is canceled. react-native-blob-util rejects the canceled task, and the catch in _downloadFile passed that to onError, so apps showed a load error while the new source was loading. A replaced download that still finished could also show its file or clear lastRNBFTask for the newer download. Give each download an id and ignore the result of one that is no longer current. Load the new source right away in componentDidUpdate instead of in the cancel callback, which react-native-blob-util doesn't call once the request has finished. Ignore a cache stat() that resolves after the source changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KqBcHkPPX7gFtJ8cnSDmV
36 tasks done
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.
When
sourcechanges while a download is still running (for example, when an auth token in the URL is refreshed),componentDidUpdatecancels the old download. Since #1019 and #1031, the stored task can be canceled, socancel()now works. But react-native-blob-util rejects a canceled task with aCanceledFetchError, and thecatchin_downloadFilepasses it toonError. An app that shows an error state fromonErrorthen hides the PDF and shows a load error, even though the new source is loading fine.The same gap lets an older download interfere with a newer one. If it finishes anyway, it can show the old file, or clear
lastRNBFTask, which by then belongs to the newer download.Changes
_cancelDownload()increments it and cancels the running task. A download whose id is no longer current ignores its result: it doesn't callonError, set state, or touchlastRNBFTask.componentDidUpdatecancels and loads the new source right away, instead of inside the cancel callback. react-native-blob-util doesn't call that callback when the request has already finished, and with the id check the order no longer matters.stat()that resolves after the source changed is ignored, so an older source can't start loading after a newer one.onErroronce.Testing
The repo has no test setup, so I tested
index.jswith Jest and react-native-blob-util mocked. The mock'scancel()rejects the task with a canceled error, like the real one.masteronErrorisn't calledonError(Error: canceled)onErrorisn't calledonError(Error: canceled)onErroris called oncefetch()throws:onErroris called, no unhandled rejectionRelated: #796 (the
lastRNBFTask.cancel is not a functioncrash, fixed by #1031), #870.🤖 Generated with Claude Code
https://claude.ai/code/session_012KqBcHkPPX7gFtJ8cnSDmV