-
Notifications
You must be signed in to change notification settings - Fork 598
Open
Description
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)
Here is the code:
<Pdf
trustAllCerts={false}
source={{ uri: URL }}
onError={(error) => {
console.log(error);
}}
onLoadComplete={(numberOfPages, filePath) => {
console.log('completed')
}}
renderActivityIndicator={() => ()}
style={style.pdf} />
GaelCO, abanobmikaeel, p-janik, GolnazMirzaie, relm923 and 5 more
Activity
Subiyel commentedon Dec 27, 2023
same issue
mdalishanali commentedon Dec 31, 2023
do you find anything?
minh-dai commentedon Jan 3, 2024
+1
kartavyaparekh96 commentedon Jan 4, 2024
+1
alex-strae commentedon Jan 5, 2024
I have the same issue when browsing fast between different unloaded PDFs and download does not have time to finish before I start fetching new PDF.
This is due to this code introduced and merged about 2 weeks ago. In index.js, line 279, with declaration of this.lastRNBFTask.
BAD CODE:
.catch(async (error) => {
this._onError(error);
});
comment it out and problem solved.
I am not an very experienced dev, but my guess is that the catch intercepts the cancel call that is supposed to be sent to ReactNativeBlobUtil and run its course there as it should, so instead it doesn't, and the code asks where the hell is my cancel method? Crash.
Well we caught the error before the cancel could do it's thing...
There is another similar catch on line 323. That one is fine, let it be.
mdalishanali commentedon Jan 5, 2024
alex-strae commentedon Jan 5, 2024
Well, what do you want to do? For me, I had to have the app stop crashing when browsing fast between PDFs. The better approach for me was to comment out the recently introduced code (that I specified in last post).
mdalishanali commentedon Jan 5, 2024
kartavyaparekh96 commentedon Jan 5, 2024
I have downgrade version @6.7.2 its working fine
alex-strae commentedon Jan 5, 2024
AminDannak commentedon Jan 10, 2024
for me, it lead to a build issue. i used 6.7.3 and it seems fine. no crash
shahid-0 commentedon Jan 11, 2024
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.
abanobmikaeel commentedon Jan 23, 2024
Also happening to me any way to solve? Happening on latest also. @shahid-0 how does one deploy with commented out code? Is that possible?
18 remaining items
tsalama commentedon Jun 6, 2024
Same issue for us!
jaiieth commentedon Jun 20, 2024
I believe the issue occurs because
this.lastRNBFTask
is unintentionally assigned aPromise
object on line 262:The issue arises because
ReactNativeBlobUtil.fetch()
returns an extendedPromise
object, which includes.cancel()
method. However, calling.catch()
on this extendedPromise
returns a normalPromise
, which does not have the.cancel()
method. This results in an error when attempting to callthis.lastRNBFTask.cancel()
.Removing the
.catch()
as suggested by @alex-strae should resolve the crash.Additionally, when calling
.cancel()
,ReactNativeBlobUtil
will reject thePromise
, triggering theonError
method.To handle this properly, modify line 321 as follows:
This change ensures that the
onError
method is only called for errors other thanReactNativeBlobUtilCanceledFetch
.Maniae commentedon Oct 10, 2024
#796 (comment) from @jaiieth is the solution that makes the most sense, and actually solves the issue 👍
This is quite strange #827 got merged as a "fix" as it only handles unMount crash situations, creates dead code in comments, and does not in fact fixes the issues of changing the pdf source url 😕.
react-native-pdf+6.7.5.patch
acuD1 commentedon Jan 1, 2025
I did tried a different approach.
This resolve completely the undefined object, as we store the fetch-task immediate after fetching it. This ensures it’s the actual task object that has the cancel() method, not a Promise.
I can now properly what it's happening afterward. A
SIGSEGV
fromFD_Done_Face
.From now on, I don't have the skills to investigate further. But clearly something nasty is going on, and probably on
react-native-blob-util
side.I am using:
No crash on IOS Simulator (18.0)