react-native-pdf: App Crash with this.lastRNBFTask.cancel is not a function
react-native
version: 0.72.4
react-native-pdf
version: 6.7.4
What platform does your issue occur on? : Both
Describe your issue as precisely as possible :
- When the PDF is loading and try to back to the screen that time app crashes
logs
TypeError: this.lastRNBFTask.cancel is not a function (it is undefined)
Screenshot
Here is the code: <Pdf trustAllCerts={false} source={{ uri: URL }} onError={(error) => { console.log(error); }} onLoadComplete={(numberOfPages, filePath) => { console.log(‘completed’) }} renderActivityIndicator={() => (<Loader />)} style={style.pdf} />
About this issue
- Original URL
- State: open
- Created 6 months ago
- Reactions: 8
- Comments: 28 (1 by maintainers)
I created this patch (patch-package) for avoid this crash:
react-native-pdf+6.7.4.patch
for me, it lead to a build issue. i used 6.7.3 and it seems fine. no crash
I was having the same issue. reinstalling the package with the latest one solved my crashing issue but then it was not crashing rather it was giving reactnativeblobutil error. by adding trustAllCerts={false} solved the not displaying pdf issue.
Even-though the patch prevents the app from crashing, it’s not actually fixing the problem, because the cancel is not triggered so the download keeps going in background, which is not ideal.
Downgrading to
6.7.3
seems a better workaround imo, as it actually cancel the download as expected.For me only @KarlosQ patch is working
I was facing the same issue. Updating to the latest version 6.7.5 has fixed it.
Would you like to create a pull request with those changes?
Hey. Adding “cache: true” to source helped me. Like this:
<Pdf source={{ uri: url, cache: true }}
I also have the same issue, when I press back button it arise the same error, then I saw your comment and try to do the same thing as you mentioned. But still it arise error. It didn’t crash the app but arise error on the onError props, but I don’t want to arise any error on the cancel. Then I commented out the below code on the line 146, and it works for me.