Skip to content

Key native attachment thumbnails on the attachment ID so they stay on screen after send - #103527

Merged
Julesssss merged 6 commits into
Expensify:mainfrom
yuvrajangadsingh:fix/98624-flicker-recyclingkey
Oct 20, 2026
Merged

Julesssss merged 6 commits into
Expensify:mainfrom
yuvrajangadsingh:fix/98624-flicker-recyclingkey

Conversation

@yuvrajangadsingh

@yuvrajangadsingh yuvrajangadsingh commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

A freshly sent attachment can render the same picture from up to three URIs in a row: the picker path, the local cache copy once cacheAttachment finishes, then the remote thumbnail URL after AddAttachment returns. BaseImage keys the expo-image view on the URI, and expo-image clears the view every time that key changes, so the thumbnail goes blank at each switch on iOS and Android.

BaseImageProps gets an optional recyclingKey. On native it replaces the URI-derived key, so the view keeps its last frame while the next source loads. On web it is pulled out of the props so the spread cannot carry it through, and web keeps its current key. ThumbnailImage and ImageWithSizeCalculation pass it down one level, and ImageRenderer keys thumbnails on their attachment ID only for uploaded attachments (the ones carrying data-expensify-source). This is narrower than the proposal's isAttachmentOrReceipt: a markdown image pointing at an Expensify receipt or chat-attachment URL passes that check too, but its ID is the positional one getHtmlWithAttachmentID adds, which an edit can reuse for a different picture. Those images, like every other markdown image, keep the URI key.

Image's memo comparator now also compares recyclingKey, so a key change reaches the view even when the source object is reused.

This stops the clearing on a key change on native. Web keeps its URI key, so the short loading placeholder web shows when the source switches is unchanged by this PR (visible in the web recordings below). It also does not change what happens when the image unmounts (expired auth token) or when a load fails (fallback icon).

Fixed Issues

$ #101928
PROPOSAL: #98624 (comment)

Tests

  1. Open any chat on iOS or Android.
  2. Tap the + button, pick an image from the gallery and send it.
  3. Verify the thumbnail appears once and stays on screen while the message sends (no blank frame when the upload finishes).
  4. Send a second image and verify the same.
  5. Send a message that is only a markdown image (![x](https://picsum.photos/200)) and verify it renders as before.
  6. Open the sent attachment and verify the full size preview opens.
  7. Send a markdown image with a dead URL (![x](https://example.com/does-not-exist.jpg)) and verify the fallback icon shows.
  8. On web, send an image and verify the thumbnail renders as before (web is not affected by the change, so the short loading placeholder on the source switch is still there).
  • Verify that no errors appear in the JS console

Console errors on the local dev web build are pre-existing (React dev prop warnings, nested button hydration warning, fingerprint CORS noise from the local proxy). None come from the changed files.

Offline tests

  1. Go offline, send an image from the gallery.
  2. Verify the thumbnail shows from the local file while the message is pending.
  3. Go back online and verify the thumbnail stays on screen when the upload completes. The chat then reloads its history and other thumbnails load as usual.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

Checked on web with Troubleshoot > Force offline: while offline the console only shows the failed network requests you get offline, and after switching back it shows the same pre-existing warnings as above. None come from the changed files.

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).
      Tested on iOS native (simulator) against the production API with a high-traffic account: the Inbox and the high-traffic workspace chat opened with no loading state, and a sent picture's thumbnail painted right away and stayed on screen until I left the chat. Android and web were not re-run with that account.
  • 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
101928-android-native.mp4

Second send, different picture:

101928-android-second.mp4
Android: mWeb Chrome
101928-android-mweb.mp4
iOS: Native
101928-ios-native-small.mp4

Second send, different picture:

101928-ios-second-small.mp4
iOS: mWeb Safari
101928-ios-mweb-small.mp4
MacOS: Chrome / Safari
101928-web-chrome.mp4

A freshly sent attachment renders the same picture from three URIs in a row: the picker path,
the local cache copy once cacheAttachment finishes, then the remote thumbnail URL after AddComment
returns. BaseImage keys the expo-image view on the URI, and expo-image clears the view every time
that key changes, so the thumbnail goes blank twice per send on iOS and Android.

BaseImageProps gets an optional recyclingKey. On native it replaces the URI-derived key; on web
it is pulled out of the props so the spread cannot carry it through and web keeps its current key.
ThumbnailImage and ImageWithSizeCalculation pass it down one level, and ImageRenderer keys
attachment thumbnails on their attachment ID. Plain markdown images have no attachment ID and
keep the URI key.
Expensify-hosted markdown images pass the attachment-or-receipt URL check
without a data-expensify-source attribute, so they were getting keyed on the
positional ID from getHtmlWithAttachmentID. Editing such a message to point at
a different picture at the same position would have kept the old frame while
the new one loaded. Key on the ID only when the image carries the uploaded
attachment attribute.
tests/README.md asks for the three sections in every test.
@melvin-bot

melvin-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

@abdulrahuman5196 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 9, 2026 07:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-09T08:02:06.570938Z 08fb7c6 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

garrettmknight
garrettmknight previously approved these changes Oct 12, 2026

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

Looks good from a product perspective.

@abdulrahuman5196

Copy link
Copy Markdown
Contributor

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Code review

The change looks correct and well scoped. I found no blocking issues. All CI checks pass except the reviewer checklist.

What I verified

  • The ID stays the same from send to server response. getUploadingAttachmentHtml writes both data-expensify-source and the client-generated data-attachment-id into the optimistic HTML. The same attachmentID is sent with AddAttachment, so the key does not change between URIs.
  • No spinner appears on the source swap. In ImageWithLoading.tsx:108-113, onLoadStart returns early once isLoadedRef is true.
  • Web is unaffected. BaseImage.tsx:17 drops the prop, so web still uses the URI key.
  • List cell recycling still works. Each attachment has a unique ID, so a reused cell gets a new key and clears.

Minor (non-blocking)

  1. Older uploaded attachments can still get a positional ID. isUploadedAttachment checks only for data-expensify-source. An attachment uploaded before data-attachment-id existed has the source attribute but no ID. getHtmlWithAttachmentID then gives it <reportActionID>_<n>. A message with text stays editable (ReportUtils.ts:6186-6187). If an edit removes the first of two such images, the second takes the first one's key. The old picture then shows briefly until the new one loads. This is rare and recovers on its own. To close the gap, also require that the ID is not positional, or document the edge case in the code comment.
  2. Hard-coded skip in the memo comparator. The Image memo comparator now lists three props by hand. That works, but the next prop added to Image has the same trap. Consider adding a short comment that new props affecting the view must be listed here.

Tests

ImageRecyclingKeyTest.tsx covers the native key, the web fallback, the memo comparator, and the three ImageRenderer cases. Each test uses Given/When/Then comments. I did not run the app; the fix targets native, and this run only had web available.


view run

@yuvrajangadsingh

Copy link
Copy Markdown
Contributor Author

@abdulrahuman5196 MelvinBot's review came back clean and garrett approved the product side. could you fill in the reviewer checklist when you get a chance?

@yuvrajangadsingh

Copy link
Copy Markdown
Contributor Author

hey @Julesssss, this one has been waiting on the reviewer checklist for about a week now. garrett approved it and MelvinBot's review came back clean, and CI is green apart from the checklist.

would you mind checking in with @abdulrahuman5196? and if he's tied up, could another C+ pick up the checklist? thanks a lot!

@abdulrahuman5196

Copy link
Copy Markdown
Contributor

Hi sorry for the delay checking now

@abdulrahuman5196

Copy link
Copy Markdown
Contributor

@yuvrajangadsingh The code looks good. Kindly fix the merge conflicts, I can work on platform specific checks then.

…ecyclingkey

# Conflicts:
#	src/components/ImageWithSizeCalculation.tsx
@yuvrajangadsingh

Copy link
Copy Markdown
Contributor Author

@abdulrahuman5196 thanks! merged main and fixed the conflict in ImageWithSizeCalculation.tsx, it's ready for the platform checks now.

@abdulrahuman5196

Copy link
Copy Markdown
Contributor

checking now

@abdulrahuman5196

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
  • 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 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
androidHybrid-0-Screen_Recording_2026-10-20_at_10.50.43.PM.mov
Android: mWeb Chrome
androidMWeb-0-Screen_Recording_2026-10-20_at_10.56.18.PM.mov
iOS: HybridApp
iosHybrid-0-Screen_Recording_2026-10-20_at_10.31.56.PM.mov
iOS: mWeb Safari
iosMWeb-0-Screen_Recording_2026-10-20_at_10.37.12.PM.mov
MacOS: Chrome / Safari
macOS-0-Screen_Recording_2026-10-20_at_9.59.04.PM.mov

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

Changes looks good and works well. Reviewers checklist is also complete.

All yours. @Julesssss

🎀 👀 🎀
C+ Reviewed

@melvin-bot
melvin-bot Bot requested a review from Julesssss October 20, 2026 17:30
@Julesssss
Julesssss merged commit 05d1f97 into Expensify:main Oct 20, 2026
35 of 38 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@OSBotify

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

Copy link
Copy Markdown
Contributor

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

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. This PR fixes a native rendering bug where a sent image thumbnail briefly went blank. It doesn't add a feature, rename anything, or make any help article sentence incorrect.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

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

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. This PR is a native bug fix that stops a newly sent image thumbnail from briefly going blank while it uploads. The app now behaves the way users already expect, so no article sentence is now incorrect.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.5.18-1 🚀

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants