Skip to content

fix: Android - Multi scan - App closes when scanning multiple receipt at once - #70026

Merged
NikkiWines merged 7 commits into
Expensify:mainfrom
TaduJR:fix-Android-Multi-scan-App-closes-when-scanning-multiple-receipt-at-once
Oct 8, 2025
Merged

NikkiWines merged 7 commits into
Expensify:mainfrom
TaduJR:fix-Android-Multi-scan-App-closes-when-scanning-multiple-receipt-at-once

Conversation

@TaduJR

@TaduJR TaduJR commented Sep 6, 2025 •

Copy link
Copy Markdown
Contributor

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.tsx
Replace memory-loading approach with path-based file references

2. Path-Based FormData Upload

Location: src/libs/prepareRequestPayload/index.native.ts
Replace memory-loading FormData with path-based approach

After Fix

  1. Camera saves photo to disk
  2. Crop and save to disk
  3. Store URI reference only
  4. Use path-based object
  5. Stream from disk during upload

Result: Zero memory loading - files remain on disk and are referenced by URI

Fixed Issues

$ #68516
PROPOSAL: #68516 (comment)

Tests

  1. Open the app
  2. Navigate to a workspace chat
  3. Start the submit expense flow for Scan
  4. Enable the multi scan mode
  5. Take 30 Receipts Picture and continue
  6. Verify the expenses created successfully and start smart scanning and verify the app did not shut down completely.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

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

@TaduJR
TaduJR requested a review from a team as a code owner September 6, 2025 17:19
@melvin-bot
melvin-bot Bot requested review from jjcoffee and removed request for a team September 6, 2025 17:19
@melvin-bot

melvin-bot Bot commented Sep 6, 2025

Copy link
Copy Markdown

@jjcoffee Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@TaduJR

TaduJR commented Sep 6, 2025 •

Copy link
Copy Markdown
Contributor Author

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.

@TaduJR
TaduJR force-pushed the fix-Android-Multi-scan-App-closes-when-scanning-multiple-receipt-at-once branch 3 times, most recently from 12c340f to 156f1b1 Compare September 8, 2025 15:57
const {uri: path = '', source} = value as File;
if (!source) {
// Handle receipt key separately (memory-efficient path-based approach)
if (key === 'receipt') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need && initiatedOffline here too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main Branch IOURequestStepScan:

  1. setMoneyRequestReceipt(transactionID, source, filename, !isEditing) - stores receipt path
  2. readFileAsync(source, filename, (file) => {...}) - converts path to File object
  3. setReceiptFiles([...receiptFiles, {file, source, transactionID}]) - stores File object
  4. Result: receiptFiles contains actual File/Blob objects ready for FormData

Fix Branch IOURequestStepScan:

  1. setMoneyRequestReceipt(transactionID, source, filename, !isEditing) - stores receipt path
  2. NO readFileAsync() call! - no File object creation
  3. setReceiptFiles([...receiptFiles, {file: fileForTracking, uri: source, transactionID}]) - stores path object
  4. 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 ?? '';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure why we need to rename this param everywhere?

@TaduJR TaduJR Sep 10, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jjcoffee

Copy link
Copy Markdown
Contributor

@TaduJR Please can you add screenshots here? Thanks 🙏

@TaduJR

TaduJR commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

@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!

@TaduJR

TaduJR commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

@jjcoffee

Copy link
Copy Markdown
Contributor

Thanks, but can you upload the video directly on GitHub please and also for the other platforms. Thanks 🙏

@TaduJR

TaduJR commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

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

> [!Important]
> You must have a Apple Developer account to run your app on a physical device. If you don't have one, you can register here: [Apple Developer Program](https://developer.apple.com/).

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.

@TaduJR
TaduJR force-pushed the fix-Android-Multi-scan-App-closes-when-scanning-multiple-receipt-at-once branch 2 times, most recently from 374a42d to 8a19a02 Compare September 15, 2025 10:51
@TaduJR

TaduJR commented Sep 16, 2025

Copy link
Copy Markdown
Contributor Author

@jjcoffee

File Splitting Rationale & Recommendation for Separate PR

Why File Splitting Was Necessary for This Fix

Platform-Specific Solutions Required

Native Platforms (Android/iOS):

  • Memory-safe approach: Use RNFS.stat() to validate files without loading content
  • Path-based processing: Pass file paths to FormData instead of loaded file objects
  • Result: 99% memory reduction (90MB → 1MB for 18 receipts)

Web Platform:

  • Blob URL approach: Continue using readFileAsync() for blob URL lifecycle management
  • Different validation: HEAD requests for blob URLs vs filesystem stat calls
  • Result: Maintains existing functionality without breaking web

Files Split & Specific Reasons

  1. IOURequestStepConfirmation → index.tsx + index.native.tsx

Why split: Completely different file validation logic

  • Native: checkFileExists(item.receipt.source) - validates without loading
  • Web: readFileAsync(item.receipt.source) - loads file for blob URL handling
  • Core difference: Native avoids memory loading entirely, web needs file content
  1. SubmitDetailsPage → index.tsx + index.native.tsx

Why split: Different receipt processing approaches

  • Native: Path-based receipt creation with checkFileExists() validation
  • Web: File loading with readFileAsync() for blob compatibility
  • Memory impact: Native creates lightweight receipt objects, web handles heavier file processing

Diff Size Impact

  • Current PR: 1,587 lines changed (includes file splitting)
  • Core fix only: ~200 lines estimated
  • File splitting adds: ~1,300+ lines making the actual fix harder to review

Recommendation: Split into 2 PRs

PR 1: File Structure (Clean, no logic changes)

  • IOURequestStepConfirmation/index.tsx (copy of original)
  • IOURequestStepConfirmation/index.native.tsx (copy of original)
  • SubmitDetailsPage/index.tsx (copy of original)
  • SubmitDetailsPage/index.native.tsx (copy of original)
  • IOURequestStepConfirmation.tsx (deleted)
  • SubmitDetailsPage.tsx (deleted)

PR 2: Memory Optimization Fix (Clear focus on actual changes)

@jjcoffee

Copy link
Copy Markdown
Contributor

@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).

@TaduJR

TaduJR commented Sep 16, 2025 •

Copy link
Copy Markdown
Contributor Author

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 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 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.

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.

@TaduJR

TaduJR commented Sep 16, 2025

Copy link
Copy Markdown
Contributor Author

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).

Ok 👍

@jjcoffee

Copy link
Copy Markdown
Contributor

@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 😄

@TaduJR
TaduJR force-pushed the fix-Android-Multi-scan-App-closes-when-scanning-multiple-receipt-at-once branch from 739c08b to 1ae7cb6 Compare September 22, 2025 19:44
@TaduJR

TaduJR commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

@jjcoffee

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camera captures are always JPEG

I don't think this is true? On iOS at least they could be HEIC right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea. You are right. I missed this one. I will refactor it to use file.type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjcoffee

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify the comment above to reflect this please

@jjcoffee

Copy link
Copy Markdown
Contributor

@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.

@jjcoffee

Copy link
Copy Markdown
Contributor

@TaduJR Let's change the first test step to just Open the app. I think QA can probably test on a physical iOS device.

@jjcoffee

jjcoffee commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
android-app-2025-09-24_10.05.16.mp4
Android: mWeb Chrome
android-chrome-2025-09-24_10.14.08.mp4
iOS: HybridApp
ios-app-2025-09-24_12.39.15.mp4
iOS: mWeb Safari
ios-safari-2025-09-24_12.47.09.mp4
MacOS: Chrome / Safari
desktop-chrome-2025-09-24_10.21.13.mp4
MacOS: Desktop
desktop-app-2025-09-24_10.26.14.mp4

@TaduJR

TaduJR commented Sep 24, 2025

Copy link
Copy Markdown
Contributor Author

@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.

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.

@TaduJR
TaduJR force-pushed the fix-Android-Multi-scan-App-closes-when-scanning-multiple-receipt-at-once branch from 140a539 to 80b4162 Compare September 26, 2025 05:47
@TaduJR

TaduJR commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

@jjcoffee

I think this issue(https://github.com/Expensify/App/issues/65571) will by fixed by this PR. I tested a lot of times with many receipt both online and offline when working on this PR to checked everything is working, even tested PDFs. But I didn't see a single Scanning expense leads to unexpected error after finishing working on this PR. What do you think?

}
};

// Native optimization: Use checkFileExists instead of readFileAsync for memory efficiency

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Sorry for the delay. Integrating the Web and Native version since they use different type was super annoying and hard.

@jjcoffee

Copy link
Copy Markdown
Contributor

I think this issue(#65571) will by fixed by this PR. I tested a lot of times with many receipt both online and offline when working on this PR to checked everything is working, even tested PDFs.

@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.

@TaduJR
TaduJR force-pushed the fix-Android-Multi-scan-App-closes-when-scanning-multiple-receipt-at-once branch from 508a3fb to ccec3b3 Compare September 28, 2025 09:53
@jjcoffee

jjcoffee commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

@TaduJR Sorry for the delay getting back to this - hopefully we'll get this completed today! Can you update the checklist in the description - it looks like it's been updated since you created the PR.

@jjcoffee jjcoffee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just needs the author checklist updating.

@melvin-bot
melvin-bot Bot requested a review from NikkiWines October 2, 2025 09:28
@NikkiWines

Copy link
Copy Markdown
Contributor

Please also merge main - that should fix the failing compiler check

@TaduJR

TaduJR commented Oct 4, 2025

Copy link
Copy Markdown
Contributor Author

Can you update the checklist in the description - it looks like it's been updated since you created the PR.

Done.

Please also merge main - that should fix the failing compiler check

Done

@jjcoffee

jjcoffee commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

All yours @NikkiWines!

@NikkiWines NikkiWines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggested changes

.at(0)
: `image_${Date.now()}.jpeg`),
type: asset.type ?? 'image/jpeg',
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty dense, especially with no comments. I think something like this might be more readable:

Suggested change
});
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',
};
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +8 to +10
itemReceiptFilename: string | undefined,
itemReceiptPath: string | undefined,
itemReceiptType: string | undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename these to just receiptXYZ as item doesn't add much value here

Suggested change
itemReceiptFilename: string | undefined,
itemReceiptPath: string | undefined,
itemReceiptType: string | undefined,
receiptFilename: string | undefined,
receiptPath: string | undefined,
receiptType: string | undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the other instances of itemReceiptXYZ in other files

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import checkFileExists from '@libs/fileDownload/checkFileExists';

/**
* Validates a receipt file and processes it for upload (Native implementation)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Validates a receipt file and processes it for upload (Native implementation)
* Validates a receipt file and processes it for upload

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/libs/prepareRequestPayload/index.ts Outdated
}

validateFormDataParameter(command, key, value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: This isn't necessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the null coalescing operator here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify the comment above to reflect this please

@TaduJR

TaduJR commented Oct 8, 2025

Copy link
Copy Markdown
Contributor Author

Can you clarify the comment above to reflect this please

Done

@NikkiWines NikkiWines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@NikkiWines
NikkiWines merged commit 39d14fe into Expensify:main Oct 8, 2025
@OSBotify

OSBotify commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify OSBotify mentioned this pull request Oct 8, 2025
62 tasks done
@OSBotify

OSBotify commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/NikkiWines in version: 9.2.28-0 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/lakchote in version: 9.2.28-5 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants