Skip to content

Keep the preview uri when resizing large image attachments on web - #102852

Merged
grgia merged 2 commits into
mainfrom
claude-preserveResizedImageUri
Oct 8, 2026
Merged

grgia merged 2 commits into
mainfrom
claude-preserveResizedImageUri

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

On web, images over 24 MiB are resized before the attachment preview opens. resizeImageIfNeeded passes the resized file through createFile, whose web branch clones it with new File(...). The File constructor doesn't copy the custom uri property, so the resized file lost its blob uri. The preview then rendered an image with an empty source, which never fires onLoad, so the spinner never went away.

This PR fixes the root cause in createFile: the web branch now copies uri onto the cloned File, matching the native branch, which already keeps uri. Every other step that creates a web attachment sets uri, so createFile was the only place that dropped it. Fixing it there also covers the other caller of resizeImageIfNeeded (the "add additional receipt" flow) and the workspace-avatar callers in Policy.ts, where the extra property is harmless.

I also added unit tests for createFile (web and native) and for resizeImageIfNeeded on web with an image over the max size. The new web tests fail without the fix and pass with it.

Fixed Issues

$ #102470
PROPOSAL: #102470 (comment)

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
// Please describe what QA needs to do to validate your changes and what areas do they need to test for regressions.

  • 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 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 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)
  • 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)
  • 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 the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Resized attachments over 24 MiB lost their blob uri, so the attachment
preview had no source and showed an endless spinner.

Co-authored-by: Qichen Zhu <QichenZhu@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team October 2, 2026 08:54
@melvin-bot melvin-bot Bot added Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web labels Oct 2, 2026
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch since I don't have push access to your fork.

To take ownership of this branch and be able to push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-preserveResizedImageUri
git checkout -b claude-preserveResizedImageUri upstream/claude-preserveResizedImageUri
git push -u origin claude-preserveResizedImageUri

Then you can close this PR and open a new one from your fork.

@MelvinBot

MelvinBot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ⚠️ partial

On standalone Android, the image attached, previewed, and sent with no stuck spinner and no related JS errors. However, this PR only changes the web branch of createFile, which Android never runs. I also couldn't create an image over 24 MiB in this session, so the resize path wasn't exercised. Treat this as a smoke test of the attachment flow, not a test of the fix.
Full-screen attachment preview rendering the image

Step Status
Navigate to a DM chatOpened a one-on-one DM with Concierge through + > Start chat. The chat header and composer loaded.
✅
Tap + > Add attachment and select the image fileTapped + > Add attachment > Choose from gallery and picked the test PNG (about 440 KB, since a file over 24 MiB couldn't be created) from the Android photo picker.
Native Android photo picker showing the test image
✅
The attachment preview shows the image, not an endless spinnerOn Android, picking one gallery image sends it right away, with no separate preview modal. The image loaded within about 2 seconds in the thread, and the full-screen attachment viewer showed it with no spinner.
Image fully loaded in the attachment thread, no spinner
Full-screen attachment preview rendering the image
✅
The image can be sent and appears in the chatThe image appears as a sent message in the Concierge DM, and Concierge replied to it as a receipt scan.
Sent image attachment in the DM
✅
No errors appear in the JS console during the flowThe AddAttachment request returned jsonCode 200 with no attachment-related exceptions. The only errors were unrelated: an AuthenticatePusher 403 (expected in the test environment) and a "dismissModal failed" navigation warning.
✅

view run · view recording

@MelvinBot

MelvinBot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ⚠️ partial

I reached a DM chat and opened the Add attachment menu, but the web test tool can't select files in the browser's file picker. No image over 24 MiB could be attached, so the resize and preview fix (steps 2–4) wasn't tested, and the tool can't read the JS console.
Concierge DM chat after Add attachment, with no file selected

Step Status
Navigate to a DM chatAfter finishing onboarding, the app opened the Concierge DM with the composer and the + menu visible.
✅
Click + > Add attachment and select the >24 MiB image fileThe + menu opened and showed Add attachment. Clicking it opens the browser's native file picker, which the web test tool can't use, since file uploads aren't supported. No file was selected.
Concierge DM chat after Add attachment, with no file selected
❌
The attachment preview shows the image, not an endless spinnerNot tested. No file could be attached.
❌
The image can be sent and appears in the chatNot tested. No file could be attached.
❌
No errors appear in the JS console during the flowNot checked. The web test tool can't read browser console logs. No error banners or broken UI appeared during onboarding or navigation.
❌

view run · view recording

Comment thread tests/unit/FileUtilsTest.ts Outdated
const file = new File(['content'], 'image.jpeg', {type: 'image/jpeg'});
file.uri = 'blob:http://localhost/image';

// When the file is cloned

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, please remove comments that don't add value like this.

@MelvinBot MelvinBot Oct 6, 2026 •

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 in d7af11b. I removed the 5 comments in the new tests that only restated the next line: both "When the file is cloned" comments, "When the image is resized", and the native test's Given/Then comments.

I kept the comments that explain why, for example that previews read uri to show the image. FileUtilsTest.ts passes (44/44) and ESLint is clean.

Co-authored-by: Qichen Zhu <QichenZhu@users.noreply.github.com>
@QichenZhu

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
    MelvinBot PRs don't require this.
  • 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
    MelvinBot PRs don't require this.
  • 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
    https://expensify.slack.com/archives/C049HHMV9SM/p1764642854883869
    https://expensify.slack.com/archives/C049HHMV9SM/p1790051358940179
  • I verified proper code patterns were followed (see Reviewing the code)
    • 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 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)
  • 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)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • 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
    • 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 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 the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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-native.mov
Android: mWeb Chrome
android-web.mov
iOS: HybridApp
ios-native.mov
iOS: mWeb Safari
ios-web.mov
MacOS: Chrome / Safari
mac-web.mov

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

MelvinBot doesn't provide test steps. My suggestion is:

Precondition: Have an image larger than 24 MiB in size and less than 50 megapixels in resolution.

Steps:

  1. Navigate to a DM.
  2. Click + > Add attachment.
  3. Select the image and upload it.
  4. Verify that the file uploads successfully. The test fails if the screen loads indefinitely.

@melvin-bot
melvin-bot Bot requested a review from grgia October 6, 2026 05:50
@QichenZhu

Copy link
Copy Markdown
Contributor

@MelvinBot mark this PR ready for review

@MelvinBot
MelvinBot marked this pull request as ready for review October 8, 2026 06:21
@MelvinBot
MelvinBot requested a review from a team as a code owner October 8, 2026 06:21
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I marked this PR ready for review.


view run

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@melvin-bot
melvin-bot Bot requested review from QichenZhu and dylanexpensify and removed request for a team October 8, 2026 06:21
@melvin-bot

melvin-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

@QichenZhu 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 October 8, 2026 06:21
@QichenZhu

Copy link
Copy Markdown
Contributor

I already reviewed.

@QichenZhu

Copy link
Copy Markdown
Contributor

@grgia, this is ready for your second review.

@grgia
grgia merged commit 76e0805 into main Oct 8, 2026
40 of 43 checks passed
@grgia
grgia deleted the claude-preserveResizedImageUri branch October 8, 2026 10:01
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

OSBotify commented Oct 8, 2026

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, 2026
90 tasks done
@OSBotify

OSBotify commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/grgia in version: 9.5.6-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

No help site update needed. This bug fix makes large image previews on web load as users expect instead of spinning forever, so no article sentence is now wrong.


view run

@IuliiaHerets

Copy link
Copy Markdown

Any QA steps here?

cc @grgia @QichenZhu @dylanexpensify

@QichenZhu

Copy link
Copy Markdown
Contributor

@IuliiaHerets QA steps:

Precondition: Have an image larger than 24 MiB in size and less than 50 megapixels in resolution.

Steps:

  1. Navigate to a DM.
  2. Click + > Add attachment.
  3. Select the image and upload it.
  4. Verify that the file uploads successfully. The test fails if the screen loads indefinitely.

Thanks!

@OSBotify

OSBotify commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 9.5.6-6 🚀

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

Bundle Size Analysis (Sentry):

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

Labels

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants