Repository navigation
fix: Android - Multi scan - App closes when scanning multiple receipt at once - #70026
Conversation
|
Hello @jjcoffee I am very sorry for the delay! This turned out to be a much deeper than initially expected. What started as a moderate Android crash fix revealed multiple interconnected issues complex state logic that needed to be preserved. After days of debugging and testing, I've implemented a comprehensive solution. Please Let me know if you have any feedback. |
12c340f to
156f1b1
Compare
| const {uri: path = '', source} = value as File; | ||
| if (!source) { | ||
| // Handle receipt key separately (memory-efficient path-based approach) | ||
| if (key === 'receipt') { |
There was a problem hiding this comment.
Don't we need && initiatedOffline here too?
There was a problem hiding this comment.
Main Branch IOURequestStepScan:
- setMoneyRequestReceipt(transactionID, source, filename, !isEditing) - stores receipt path
- readFileAsync(source, filename, (file) => {...}) - converts path to File object
- setReceiptFiles([...receiptFiles, {file, source, transactionID}]) - stores File object
- Result: receiptFiles contains actual File/Blob objects ready for FormData
Fix Branch IOURequestStepScan:
- setMoneyRequestReceipt(transactionID, source, filename, !isEditing) - stores receipt path
- NO readFileAsync() call! - no File object creation
- setReceiptFiles([...receiptFiles, {file: fileForTracking, uri: source, transactionID}]) - stores path object
- Result: receiptFiles contains {uri: 'file://...', name: '...', type: '...'} objects
Why This Breaks:
Main branch with && initiatedOffline:
- Online: Receipts processed as regular FormData → receiptFiles has File objects → works
- Offline: Special file handling → works
Fix branch with && initiatedOffline:
- Online: Receipts processed as regular FormData → receiptFiles has {uri, name, type} objects → FAILS (Unexpected error when uploading receipt)
- Without condition: path-based approach → works
| @@ -23,8 +23,8 @@ function ReceiptCell({transactionItem, isSelected, style}: {transactionItem: Tra | |||
| const backgroundStyles = isSelected ? StyleUtils.getBackgroundColorStyle(theme.buttonHoveredBG) : StyleUtils.getBackgroundColorStyle(theme.border); | |||
| const {hovered, bind} = useHover(); | |||
| const isEReceipt = transactionItem.hasEReceipt && !hasReceiptSource(transactionItem); | |||
| let source = transactionItem?.receipt?.source ?? ''; | |||
| let previewSource = transactionItem?.receipt?.source ?? ''; | |||
| let source = transactionItem?.receipt?.uri ?? ''; | |||
There was a problem hiding this comment.
Also, I'm not sure why we need to rename this param everywhere?
There was a problem hiding this comment.
I changed the core Receipt type definition from source?: string to uri?: string because
- Consistency with React Native file handling patterns (which use uri)
- Alignment with our memory-efficient path-based approach
- To avoid typecasting on prepareRequestPayload and IOURequestStepScan
|
@TaduJR Please can you add screenshots here? Thanks 🙏 |
I can add demo video even better. The reason I didn't upload earlier is because I wanted your feedback on the way its going first. Thank you! |
|
Thanks, but can you upload the video directly on GitHub please and also for the other platforms. Thanks 🙏 |
|
Great. I will upload it to GitHub directly. But about one iOS: App, and iOS: Safari, Chrome on Physical Devices apple developer account is required App/contributingGuides/HOW_TO_BUILD_APP_ON_PHYSICAL_IOS_DEVICE.md Lines 11 to 12 in 11ff8e8 I tried to register but it its giving me Unable to Proceed on Apple Developer Website. since last week. This is needed because camera is needed on physical phone for testing the fix. Uploading Android mWeb: Chrome for now. |
374a42d to
8a19a02
Compare
|
File Splitting Rationale & Recommendation for Separate PR Why File Splitting Was Necessary for This Fix Platform-Specific Solutions Required Native Platforms (Android/iOS):
Web Platform:
Files Split & Specific Reasons
Why split: Completely different file validation logic
Why split: Different receipt processing approaches
Diff Size Impact
Recommendation: Split into 2 PRs PR 1: File Structure (Clean, no logic changes)
PR 2: Memory Optimization Fix (Clear focus on actual changes) |
|
@TaduJR Please don't use LLMs for posting comments (or at the very least, prompt them better 😄). I know you've said that you use them to enhance your English, but honestly these outputs are just really verbose and difficult to parse, which ends up wasting everyone's time. I don't believe your comment above needed to be more than a couple of sentences, for example. I don't know what you're English level is, but I'm guessing a better strategy might be to write a simple, concise comment in your native language and ask an LLM to translate it to English instead. That being said, I'm not sure if there's any big benefit to splitting this into multiple PRs. I think it'd usually make more sense to do when dealing with multiple features, to avoid making a PR hard to test (particularly for QA). |
I am very sorry if I wasted your time @jjcoffee. First I was writing my own english but become less confident since I thought my short comment won't make sense it to you and wanted to make it more insightful by prompting by bad english analysis to give me a most insight inorder for you to get my whole idea and why. I think its not working. I am guessing we should communicate step by step even though there might be a misunderstanding due to my english inconfidence. I am very sorry again. Feel ashamed with my english inconfident.
I made it accidentally long when trying to make it insightful 😅. To not leave you ambiguous. That backfired i guess. Thank you so much for you feedback ❤️. I will make my short comment first and if it ambiguous then I will explain more. I think that is more great approach. |
Ok 👍 |
|
@TaduJR What's the status here? Were you able to test on iOS? I see a lot of commits, but it's hard to tell if this is ready to review or not 😄 |
739c08b to
1ae7cb6
Compare
|
I tried to register Apple Developer Account, It's still not working. But since the issue was occurring because of adding multiple images, the main issue was not camera, I added the iOS demo using local image loading multiple receipt loading. The PR is ready for a review. |
| Log.warn('Error reading photo'); | ||
| }, | ||
| ); | ||
| // Ensure camera receipts have proper type (camera captures are always JPEG) |
There was a problem hiding this comment.
camera captures are always JPEG
I don't think this is true? On iOS at least they could be HEIC right?
There was a problem hiding this comment.
Yea. You are right. I missed this one. I will refactor it to use file.type
There was a problem hiding this comment.
Sorry I thought the comment was on gallery upload earlier. For camera upload I think the react-native-vision-camera always uses always jpeg from my research on their repo regardless of iOS or Android. That's why I commented the line 702. Please check out this link for more https://github.com/mrousavy/react-native-vision-camera/issues/2357
There was a problem hiding this comment.
Can you clarify the comment above to reflect this please
|
@TaduJR Can you confirm if you originally reproduced the crash with 30 images? I'd like to confirm the fix by reproducing on main first with the Android emulator, but even with 30 I don't get a crash. |
|
@TaduJR Let's change the first test step to just |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppandroid-app-2025-09-24_10.05.16.mp4Android: mWeb Chromeandroid-chrome-2025-09-24_10.14.08.mp4iOS: HybridAppios-app-2025-09-24_12.39.15.mp4iOS: mWeb Safariios-safari-2025-09-24_12.47.09.mp4MacOS: Chrome / Safaridesktop-chrome-2025-09-24_10.21.13.mp4MacOS: Desktopdesktop-app-2025-09-24_10.26.14.mp4 |
Yes, It is still reproducible on both latest main, and prod android app. Capturing crashes it and loading multiple receipt from gallery shows infinite loading. But Maybe Its because you are using emulator. Idk if emulators have a better memory management or maybe physical phones have strict memory allocation. Could you try to reproduce it on android physical devices? It's 100% reproducible on physical phone. |
140a539 to
80b4162
Compare
|
I think this issue( |
| } | ||
| }; | ||
|
|
||
| // Native optimization: Use checkFileExists instead of readFileAsync for memory efficiency |
There was a problem hiding this comment.
Actually I've just realised that duplicating the entire IOURequestStepConfirmation for the native implementation is going to be a maintainability nightmare (I already see we've drifted from main here). Let's instead create a helper with a native-specific implementation for the parts you've added here.
There was a problem hiding this comment.
Done. Sorry for the delay. Integrating the Web and Native version since they use different type was super annoying and hard.
@TaduJR Can you post on that issue with your findings? They can then hold on this PR and see if it's still happening after it hits staging. |
508a3fb to
ccec3b3
Compare
…when-scanning-multiple-receipt-at-once
…when-scanning-multiple-receipt-at-once
…when-scanning-multiple-receipt-at-once
jjcoffee
left a comment
There was a problem hiding this comment.
LGTM! Just needs the author checklist updating.
|
Please also merge |
…when-scanning-multiple-receipt-at-once
Done.
Done |
|
All yours @NikkiWines! |
NikkiWines
left a comment
There was a problem hiding this comment.
Some suggested changes
| .at(0) | ||
| : `image_${Date.now()}.jpeg`), | ||
| type: asset.type ?? 'image/jpeg', | ||
| }); |
There was a problem hiding this comment.
This is pretty dense, especially with no comments. I think something like this might be more readable:
| }); | |
| const processAssetWithFallbacks = (asset: Asset): Asset => { | |
| // Generate fallback name: extract from URI if available, otherwise use timestamped default | |
| const fallbackName = asset.uri ? asset.uri.substring(asset.uri.lastIndexOf('/') + 1).split('?').at(0) : `image_${Date.now()}.jpeg`; | |
| const fileName = asset.fileName ?? fallbackName; | |
| return { | |
| ...asset, | |
| fileName, | |
| // Default to JPEG if no type specified | |
| type: asset.type ?? 'image/jpeg', | |
| }; | |
| } |
| itemReceiptFilename: string | undefined, | ||
| itemReceiptPath: string | undefined, | ||
| itemReceiptType: string | undefined, |
There was a problem hiding this comment.
let's rename these to just receiptXYZ as item doesn't add much value here
| itemReceiptFilename: string | undefined, | |
| itemReceiptPath: string | undefined, | |
| itemReceiptType: string | undefined, | |
| receiptFilename: string | undefined, | |
| receiptPath: string | undefined, | |
| receiptType: string | undefined, |
There was a problem hiding this comment.
Same for the other instances of itemReceiptXYZ in other files
| import checkFileExists from '@libs/fileDownload/checkFileExists'; | ||
|
|
||
| /** | ||
| * Validates a receipt file and processes it for upload (Native implementation) |
There was a problem hiding this comment.
| * Validates a receipt file and processes it for upload (Native implementation) | |
| * Validates a receipt file and processes it for upload |
| } | ||
|
|
||
| validateFormDataParameter(command, key, value); | ||
|
|
There was a problem hiding this comment.
NAB: This isn't necessary
| newReceiptFiles.push({file, source: file.uri ?? '', transactionID}); | ||
| // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
| setMoneyRequestReceipt(transactionID, file.uri ?? '', file.name || '', true); | ||
| setMoneyRequestReceipt(transactionID, file.uri || '', file.name || '', true, file.type); |
There was a problem hiding this comment.
Why did you change the null coalescing operator here
There was a problem hiding this comment.
I made that to be consistent with others but on second thought we don't need to suppress the linter error at all and we should should use null coalescing as suggested by the linter.
| Log.warn('Error reading photo'); | ||
| }, | ||
| ); | ||
| // Ensure camera receipts have proper type (camera captures are always JPEG) |
There was a problem hiding this comment.
Can you clarify the comment above to reflect this please
…when-scanning-multiple-receipt-at-once
Done |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/NikkiWines in version: 9.2.28-0 🚀
|
|
🚀 Deployed to production by https://github.com/lakchote in version: 9.2.28-5 🚀
|
Explanation of Change
Eliminate
readFileAsync()usage and implement path-based file handling:1. Path-Based Receipt Capture
Location:
src/pages/iou/request/step/IOURequestStepScan/index.native.tsxReplace memory-loading approach with path-based file references
2. Path-Based FormData Upload
Location:
src/libs/prepareRequestPayload/index.native.tsReplace memory-loading FormData with path-based approach
After Fix
Result: Zero memory loading - files remain on disk and are referenced by URI
Fixed Issues
$ #68516
PROPOSAL: #68516 (comment)
Tests
Offline tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))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.ScrollViewcomponent to make it scrollable when more elements are added to the page.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_Native_Compressed.mp4
Android: mWeb Chrome
Android_mWeb_Compressed.mp4
iOS: Native
iOS_Native_Compressed.mp4
iOS: mWeb Safari
mSafari_Compressed.mp4
MacOS: Chrome / Safari
Safari.mp4
MacOS: Desktop
Desktop.mp4