You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
App Crash with this.lastRNBFTask.cancel is not a function #796
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.
On Fri, Jan 5, 2024 at 3:04 PM alex-strae ***@***.***> wrote:
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 catched 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.
—
Reply to this email directly, view it on GitHub
<#796 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AV7OUDU2GGWOLRCCXOFOW3TYM7CJFAVCNFSM6AAAAABBAYXAFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZYGM3TMNRZGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
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).
Yes, because the code causing the issue was introduced just two weeks ago.HälsningarAlex5 jan. 2024 kl. 11:26 skrev kartavyaparekh96 ***@***.***>:
I have downgrade version @6.7.2 its working fine
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
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.
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.
Make change(s) in node_modules, cd /ios , run pod install and you’re good.HälsningarAlex23 jan. 2024 kl. 14:34 skrev Abanob Mikaeel ***@***.***>:
Also happening to me any way to solve? Happening on latest also
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
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.
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.
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.
I updated to 6.7.5 recently (RN 0.74.1, Android: Fabric Disabled, Bridgeless Disabled, TurboModules enabled | iOS new architecture disabled) and the problem was back. Crash when quickly changing source for PdfViewer (this.lastRNBFTask.cancel is not a function) by scrolling between different "dates" with different pdf sources.
I applied Karlos patch. While it does work, if I scroll back to a date I just skipped, it's noticeable that there was no cancel fired. The PDF was loaded in the background even though I switched to another date.
The reason for this should be that the error manifested itself if this.lastRNBFTask.cancel was undefined, as in it was falsy. This means the patch will make the function never run if it doesn't exist. While that is good, wouldn't it be better if the function existed for us and we could run it? Yes.
I tried my old patch I posted a while ago which is simple: comment out catch-code on line 279, after the creation of the lastRNBFTask object creation.
And now everything works as intended (I think?). The reasons it works, I believe, is that when we reset the pdf source fast, there is an error in the creation of the lastRNBFTask object. This error get's caught in the catch and the lastRNBFTask object gets corrupted, or at least interrupted in its creation. There is no cancel method available, and that causes the crash (.cancel is undefined).
By disabling the catch, the lastRNBFTask object can get created with all it's helper methods (such as the .cancel) even though another process before it such as the .progress or .fetch had an error.
Reacted by Ian Duke, Maxime BARRY and Felipe da Silva Pinho
I was getting a crash with stacktrace TypeError: undefined is not a function at componentDidUpdate. This no longer crashes with the catch block commented out.
This happens to us when pressing back button on Stack (expo-router) while PDF is not completely loaded. While not a proper solution, we have made a workaround by preventing back until PDF is loaded (https://reactnavigation.org/docs/preventing-going-back/). Looking forward to the proper fix.
This happens to us when pressing back button on Stack (expo-router) while PDF is not completely loaded. While not a proper solution, we have made a workaround by preventing back until PDF is loaded (https://reactnavigation.org/docs/preventing-going-back/). Looking forward to the proper fix.
I believe the issue occurs because this.lastRNBFTask is unintentionally assigned a Promise object on line 262:
this.lastRNBFTask = ReactNativeBlobUtil.config({
// response data will be saved to this path if it has access rights.
path: tempCacheFile,
trusty: this.props.trustAllCerts,
})
.fetch(
source.method ? source.method : 'GET',
source.uri,
source.headers ? source.headers : {},
source.body ? source.body : ""
)
// listen to the download progress event
.progress((received, total) => {
if (this.props.onLoadProgress) {
this.props.onLoadProgress(received / total);
}
if (this._mounted) {
this.setState({ progress: received / total });
}
})
.catch(async (error) => { // <- remove this
this._onError(error);
});
The issue arises because ReactNativeBlobUtil.fetch() returns an extended Promise object, which includes .cancel() method. However, calling .catch() on this extended Promise returns a normal Promise, which does not have the .cancel() method. This results in an error when attempting to call this.lastRNBFTask.cancel().
Removing the .catch() as suggested by @alex-strae should resolve the crash.
Additionally, when calling .cancel(), ReactNativeBlobUtil will reject the Promise, triggering the onError method.
To handle this properly, modify line 321 as follows:
#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 😕.
_downloadFile=async(source,cacheFile)=>{console.log('Download file');// 1. Cancel any existing fetch-taskif(this.lastRNBFTask&&typeofthis.lastRNBFTask.cancel==='function'){console.log('Cancel last task');this.lastRNBFTask.cancel(()=>{console.log('Last task canceled');});this.lastRNBFTask=null;}// 2. Prepare the temp file path and ensure any leftover file is removedconsttempCacheFile=cacheFile+'.tmp';awaitthis._unlinkFile(tempCacheFile);// 3. Create the actual fetch-task objectconsttask=ReactNativeBlobUtil.config({path: tempCacheFile,trusty: this.props.trustAllCerts,}).fetch(source.method??'GET',source.uri,source.headers??{},source.body??'');// 4. Assign the fetch-task object to this.lastRNBFTaskthis.lastRNBFTask=task;// 5. Now chain the progress, then, and catchtask.progress((received,total)=>{this.props.onLoadProgress?.(received/total);if(this._mounted){this.setState({progress: received/total});}}).then(async(res)=>{// Clear the reference to the taskthis.lastRNBFTask=null;// Validate the file size if headers include Content-Length (to detect partial downloads)if(res?.respInfo?.headers&&!res.respInfo.headers['Content-Encoding']&&!res.respInfo.headers['Transfer-Encoding']&&res.respInfo.headers['Content-Length']){constexpectedContentLength=res.respInfo.headers['Content-Length'];letactualContentLength;try{constfileStats=awaitReactNativeBlobUtil.fs.stat(res.path());if(!fileStats||!fileStats.size){thrownewError('FileNotFound:'+source.uri);}actualContentLength=fileStats.size;}catch(error){thrownewError('DownloadFailed:'+source.uri);}if(expectedContentLength!=actualContentLength){thrownewError('DownloadFailed:'+source.uri);}}// Move the downloaded file from temp to the final locationawaitthis._unlinkFile(cacheFile);awaitReactNativeBlobUtil.fs.cp(tempCacheFile,cacheFile);if(this._mounted){this.setState({path: cacheFile,isDownloaded: true,progress: 1,});}// Clean up the temp fileawaitthis._unlinkFile(tempCacheFile);}).catch(async(error)=>{console.log('Download error:',error);// Clean up temp filesawaitthis._unlinkFile(tempCacheFile);awaitthis._unlinkFile(cacheFile);this._onError(error);// // If it wasn't a user-cancel, call the error callback// if (error.name !== 'ReactNativeBlobUtilCanceledFetch') {// this._onError(error);// }});};
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 from FD_Done_Face.
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?
alex-strae commentedon Jan 23, 2024
UgurGumushan commentedon Jan 31, 2024
+1
This is a blocker and I can't update this package anymore
5 remaining items
KarlosQ commentedon Mar 7, 2024
@wonday Do you see a solution for this 6.7.4 regression?
UgurGumushan commentedon Mar 11, 2024
Would you like to create a pull request with those changes?
kamiltenkai commentedon Mar 12, 2024
Hey. Adding "cache: true" to source helped me. Like this:
<Pdf source={{ uri: url, cache: true }}nawazokz commentedon Mar 15, 2024
thanks bro, that's work for me
dariyd commentedon Mar 26, 2024
This worked for me. Many thanks!
wonday commentedon Mar 26, 2024
Would you like to create a pull request with those changes?
abanobmikaeel commentedon Apr 9, 2024
Isn't that code kinda overwriting needed functionality? @wonday
As @elkinjosetm mentioned:
chandwho commentedon Apr 23, 2024
I was facing the same issue. Updating to the latest version 6.7.5 has fixed it.
alex-strae commentedon May 13, 2024
I updated to 6.7.5 recently (RN 0.74.1, Android: Fabric Disabled, Bridgeless Disabled, TurboModules enabled | iOS new architecture disabled) and the problem was back. Crash when quickly changing source for PdfViewer (this.lastRNBFTask.cancel is not a function) by scrolling between different "dates" with different pdf sources.
I applied Karlos patch. While it does work, if I scroll back to a date I just skipped, it's noticeable that there was no cancel fired. The PDF was loaded in the background even though I switched to another date.
The reason for this should be that the error manifested itself if this.lastRNBFTask.cancel was undefined, as in it was falsy. This means the patch will make the function never run if it doesn't exist. While that is good, wouldn't it be better if the function existed for us and we could run it? Yes.
I tried my old patch I posted a while ago which is simple: comment out catch-code on line 279, after the creation of the lastRNBFTask object creation.
/*
.catch(async (error) => {
this._onError(error);
});
*/
And now everything works as intended (I think?). The reasons it works, I believe, is that when we reset the pdf source fast, there is an error in the creation of the lastRNBFTask object. This error get's caught in the catch and the lastRNBFTask object gets corrupted, or at least interrupted in its creation. There is no cancel method available, and that causes the crash (.cancel is undefined).
By disabling the catch, the lastRNBFTask object can get created with all it's helper methods (such as the .cancel) even though another process before it such as the .progress or .fetch had an error.
iduke-rbi commentedon May 23, 2024
The above suggestion from @alex-strae worked for me with Expo 50 and 6.7.5.
I was getting a crash with stacktrace
TypeError: undefined is not a functionat componentDidUpdate. This no longer crashes with the catch block commented out.roniemartinez commentedon Jun 6, 2024
This happens to us when pressing back button on Stack (
expo-router) while PDF is not completely loaded. While not a proper solution, we have made a workaround by preventing back until PDF is loaded (https://reactnavigation.org/docs/preventing-going-back/). Looking forward to the proper fix.tsalama commentedon Jun 6, 2024
Same issue for us!
jaiieth commentedon Jun 20, 2024
I believe the issue occurs because
this.lastRNBFTaskis unintentionally assigned aPromiseobject on line 262:The issue arises because
ReactNativeBlobUtil.fetch()returns an extendedPromiseobject, which includes.cancel()method. However, calling.catch()on this extendedPromisereturns 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(),ReactNativeBlobUtilwill reject thePromise, triggering theonErrormethod.To handle this properly, modify line 321 as follows:
This change ensures that the
onErrormethod 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.patchacuD1 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
SIGSEGVfromFD_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-utilside.I am using:
No crash on IOS Simulator (18.0)