Skip to content

Guard against empty receipt source in ReceiptFileValidator#89313

Merged
Julesssss merged 14 commits into
mainfrom
claude-receiptFileValidatorEmptySourceFix
May 7, 2026
Merged

Guard against empty receipt source in ReceiptFileValidator#89313
Julesssss merged 14 commits into
mainfrom
claude-receiptFileValidatorEmptySourceFix

Conversation

@MelvinBot
Copy link
Copy Markdown
Contributor

@MelvinBot MelvinBot commented Apr 30, 2026

Explanation of Change

When a browser page refreshes, blob:// URLs in the transaction draft become invalid. ReceiptFileValidator detects this and calls onFailure, which clears the receipt source to ''. On re-render, the non-local file branch (isLocalFile('') returns false) adds the receipt with empty source to receiptFiles because it only checks item.receipt (truthy object) — not whether the source is actually present. This hides the loading state and enables the "Create Expense" button with no receipt preview.

This PR adds an itemReceiptPath truthiness check so that receipts with an empty source are not treated as valid non-local files.

Fixed Issues

$ #88975
PROPOSAL: #88975 (comment)

Tests

  1. Navigate to workspace chat or Click global +
  2. Choose Scan
  3. Upload a receipt to create an expense
  4. Refresh the page
  5. Observe the receipt preview and button state
  6. Verify the user is redirected to Create Expense flow
  • Verify that no errors appear in the JS console

Offline tests

This change only affects how receipt sources are validated after page refresh. Offline behavior is unchanged — the guard only prevents empty-source receipts from being treated as valid non-local files. No new offline-specific flows are introduced.

QA Steps

  1. Navigate to workspace chat or Click global +
  2. Choose Scan
  3. Upload a receipt to create an expense
  4. Refresh the page
  5. Observe the receipt preview and button state
  6. Verify the user is redirected to Create Expense flow
  • 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
  • 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 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

N/A — no UI changes, logic-only fix

Android: mWeb Chrome

N/A — no UI changes, logic-only fix

iOS: Native

N/A — no UI changes, logic-only fix

iOS: mWeb Safari

N/A — no UI changes, logic-only fix

MacOS: Chrome / Safari

N/A — no UI changes, logic-only fix

Add itemReceiptPath truthiness check so that receipts with empty
source (after blob URL expiry clears the source) are not added to
receiptFiles, preventing the confirmation page from showing an
enabled button with no receipt preview.

Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 5, 2026

@MelvinBot request my review

@MelvinBot MelvinBot requested a review from FitseTLT May 5, 2026 15:42
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Review requested from FitseTLT

@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 5, 2026

@MelvinBot the test steps should be

Navigate to workspace chat or Click global +
Choose Scan
Upload a receipt to create an expense
Refresh the page
Verify the user is redirected to Create Expense flow.

@MelvinBot
Copy link
Copy Markdown
Contributor Author

Updated the Tests and QA Steps sections with the provided test steps ✅

@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 5, 2026

@MelvinBot complete your checklist and make it ready for review


if (!isLocalFile) {
if (item.receipt) {
if (item.receipt && itemReceiptPath) {
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.

The check should be added for the above line @MelvinBot

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.

Added the itemReceiptPath guard to the isLocalFileFileUtils call as well — ReceiptFileValidator.tsx:62. Pushed in a91fbec.

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.

Ok @MelvinBot add &&itemReceiptPath check on line 64 that's all that is needed remove other changes.

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.

no you added it on 65 @MelvinBot

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.

Moved the itemReceiptPath guard to line 64 (if (!isLocalFile && itemReceiptPath)) and reverted line 65 back to if (item.receipt). Pushed in 0f67f2c.

@MelvinBot MelvinBot marked this pull request as ready for review May 5, 2026 15:49
@MelvinBot MelvinBot requested a review from a team as a code owner May 5, 2026 15:49
@melvin-bot melvin-bot Bot requested review from FitseTLT and JmillsExpensify and removed request for a team May 5, 2026 15:49
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 5, 2026

@FitseTLT 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]

@melvin-bot melvin-bot Bot removed the request for review from a team May 5, 2026 15:49
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Completed the PR Author Checklist and marked the PR as ready for review.

Note for co-author: The following items are left unchecked as they require manual verification:

  • Offline testing on device
  • High Traffic account testing
  • Screenshots/videos on all platforms
  • Platform-specific test runs

Please complete these if applicable before merge.

Co-authored-by: FitseTLT <48335213+FitseTLT@users.noreply.github.com>
Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner May 5, 2026 15:52
@melvin-bot melvin-bot Bot requested review from Julesssss and removed request for a team May 5, 2026 15:52
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 5, 2026

@Julesssss 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]

Per review feedback, remove the isLocalFile guard change and keep
only the && itemReceiptPath check in the if (item.receipt) condition.

Co-authored-by: FitseTLT <73498291+FitseTLT@users.noreply.github.com>
Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Done — reverted the isLocalFile guard change and kept only the && itemReceiptPath check on the if (item.receipt) line. The PR now has a single-line change.

Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 5, 2026

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
  • 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.
  • [ x 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: mWeb Chrome
2026-05-05.23-40-53.mp4
iOS: HybridApp
iOS: mWeb Safari
2026-05-05.23-46-13.mp4
MacOS: Chrome / Safari
2026-05-05.23-42-25.mp4

Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Fixed the failing check: the test mock for Navigation was missing getActiveRouteWithoutParams, which is called in ReceiptFileValidator.tsx:104. Added the missing mock function.

@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 6, 2026

@MelvinBot fix jest failure

…ssing Navigation mock

- Add early return in ReceiptFileValidator when no receipt path/filename exists
  (e.g. distance requests), preventing false onFailure and draft removal
- Add getActiveRouteWithoutParams to Navigation mock in test

Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Fixed the jest failure. Two issues:

  1. Missing Navigation mock: getActiveRouteWithoutParams was not mocked in the test, causing a TypeError (introduced by main merge).

  2. Receipt-less transactions falling through validation: The PR's guard (!isLocalFile && itemReceiptPath) caused transactions without receipts (e.g. distance requests) to fall through to validateReceiptFile, which triggered onFailure and removed draft transactions before the test could press "Create expense". Added an early return when neither receipt path nor filename exists.

Comment on lines +62 to +67

// No receipt at all (e.g. distance requests) — nothing to validate
if (!itemReceiptPath && !itemReceiptFilename) {
return Promise.resolve();
}

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.

@MelvinBot pls remove this change

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.

Removed the early return guard block. Pushed in 42bb7b0.

Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 6, 2026

@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 7, 2026

@MelvinBot revert the current change

  1. below
    add a variable
        let resetInitialTransactionReceipt = false;

  1. change this to
// We don't directly reset the receipt here because this will cause the transaction to change
                        // and retrigger the effect before the promise is resolved which will cause ignoring of the redirection.
                        resetInitialTransactionReceipt = true;
  1. and before here
 if (resetInitialTransactionReceipt) {
                setMoneyRequestReceipt(initialTransactionID, '', '', true, '');
            }

Move setMoneyRequestReceipt call from inside the onFailure callback
to after Promise.all resolves, preventing the transaction change from
retriggering the effect before the promise chain completes.

Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 7, 2026

@MelvinBot U forgot to revert all the previous changes before making the latest changes 😢

The previous commit kept the original `&& itemReceiptPath` guard on
the non-local file check. This reverts that guard so only the deferred
receipt reset logic remains as the fix.

Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Reverted the original && itemReceiptPath guard — the PR now only contains the deferred receipt reset changes. Sorry about that!

@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 7, 2026

@MelvinBot remove changes to tests/ui/components/IOURequestStepConfirmationPageTest.tsx

Co-authored-by: Fitsum Abebe <FitseTLT@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Reverted changes to tests/ui/components/IOURequestStepConfirmationPageTest.tsx — removed the added getActiveRouteWithoutParams mock.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...request/step/confirmation/ReceiptFileValidator.tsx 60.52% <66.66%> (+0.52%) ⬆️
... and 127 files with indirect coverage changes

Copy link
Copy Markdown
Contributor

@FitseTLT FitseTLT left a comment

Choose a reason for hiding this comment

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

LGTM

@FitseTLT
Copy link
Copy Markdown
Contributor

FitseTLT commented May 7, 2026

U can proceed @Julesssss

Copy link
Copy Markdown
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

Looking good. Comment is brief and clear

@Julesssss Julesssss merged commit c91b3d2 into main May 7, 2026
54 of 66 checks passed
@Julesssss Julesssss deleted the claude-receiptFileValidatorEmptySourceFix branch May 7, 2026 17:55
@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented May 7, 2026

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

🚧 @Julesssss has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented May 8, 2026

🚀 Deployed to staging by https://github.com/Julesssss in version: 9.3.69-0 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot
Copy link
Copy Markdown
Contributor Author

No help site changes are required for this PR.

This is a purely internal bug fix that defers a setMoneyRequestReceipt call until after Promise.all resolves to prevent a race condition on browser page refresh. It does not change any user-facing features, workflows, UI labels, or settings — the existing help site documentation remains accurate.

@lanitochka17
Copy link
Copy Markdown

Deploy Blocker ##90025 was identified to be related to this PR.

@OSBotify
Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Beamanator in version: 9.3.69-18 🚀

platform result
🕸 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.

5 participants