Repository navigation
Fix react-native-pdf throws undefined is not a function - #106351
Conversation
…wnload is canceled
|
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Fixing oxlint and cspell... |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48841776d1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
I'll take a look at this PR after an hour |
Codecov Report✅ All modified and coverable lines are covered by tests. |
|
@suneox how is this looking? |
| + // ignores its result, so there's no need to wait for the cancel callback, which react-native-blob-util | ||
| + // doesn't call when the request has already finished. | ||
| + this._cancelDownload(); | ||
| + this._loadFromSource(this.props.source); |
There was a problem hiding this comment.
NAB: wonday/react-native-pdf#1057 also ignores a cache stat() in _loadFromSource that settles after the source changed (isCurrentSource), but this patch doesn't
Reviewer Checklist
Screenshots/VideosAndroid: mWeb ChromeNot available iOS: mWeb SafariNot available MacOS: Chrome / SafariCleanShot.2026-11-10.at.10.05.54.3.mp4 |
|
Thank you. I will wait for Mariusz to address this. |
|
Addressed! |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.36-0 🚀
|
|
🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.5.36-0 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Sentry APP-NAP is an unhandled
TypeError: undefined is not a functionfromreact-native-pdf7.0.2. It happens when a native PDF's URL changes while the PDF is still downloading. In the events I checked, that's a cold start that restores the receipt screen, where theencryptedAuthTokenin the receipt URL is refreshed during the first download._downloadFilestores the promise returned by.catch()inlastRNBFTaskinstead of thereact-native-blob-utiltask, so it never hascancel(). When the URL changes,componentDidUpdateskips the cancel and starts a new download, which then callslastRNBFTask.cancel()and throws._prepareFiledoesn't await_downloadFile, so the error becomes an unhandled promise rejection.This PR adds
react-native-pdf+7.0.2+007+fix-cancel-download-task.patch, which:cancel()exists before calling it.onError(whichPDFViewwould show as a load failure) and an old download can't replace the current PDF.onErroronce, instead of also copying it to the cache and showing it.Bumping
react-native-pdfisn't enough. 7.0.5 fixes the crash (wonday/react-native-pdf#1031) but still passes the cancellation toonError, so the receipt would show the load error. I opened wonday/react-native-pdf#1057 for that, and the patch can be dropped once it's released.tests/unit/ReactNativePDFDownloadTest.tsxruns the real (patched)react-native-pdfJS withreact-native-blob-utilmocked. All 3 cases fail without the patch.Fixed Issues
$ #106338
PROPOSAL:
Tests
undefined is not a functionor unhandled promise rejection error appears. Onmainit does. The receipt then shows only the file name: once the session expires, the receipt URL carries the invalidated token, the server rejects it, and the PDF fails to load. There's no crash. Close the receipt, reopen it a few seconds later once the app has re-authenticated, and verify the PDF loads.Offline tests
QA Steps
Same as tests, iOS and Android only
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
android-106338-pr-test-steps-invalidate-with-delay.mp4
Android: mWeb Chrome
iOS: Native
ios-106338-pr-test-steps-invalidate-with-delay.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari