Skip to content

Keep edited file attachments laid out as cards - #101717

Merged
lakchote merged 29 commits into
Expensify:mainfrom
mukhrr:fix/99385-regressions
Oct 23, 2026
Merged

lakchote merged 29 commits into
Expensify:mainfrom
mukhrr:fix/99385-regressions

Conversation

@mukhrr

@mukhrr mukhrr commented Sep 21, 2026 •

Copy link
Copy Markdown

Explanation of Change

Editing a comment that holds a file attachment broke it three ways: the server returns the edited anchor without its attachment attributes, so the file rendered as a plain link; an edit saved while the upload was still in flight dropped the file; and a renamed file reverted its name or lost its extension on download. The comment's own markup now identifies the attachment, a deferred edit replays once the upload lands, and the new name travels with the queued file.

Fixed Issues

$ #98743
$ #101689
$ #101692
$ #101744
PROPOSAL:

Tests

Precondition: two .csv files, one named with underscores such as merchant_rules_import_mock.csv and one with a non-English name such as Ăn dặm.csv.

  1. Open any chat. Type some text, click the plus, choose Add attachment, pick merchant_rules_import_mock.csv and send. Wait for the upload to finish.
  2. Right click the message, choose Edit comment, change the text and save.
  3. Verify the file still shows inside a bordered card with a download icon, not a plain blue link, the card is at full height, and (edited) sits next to the text.
  4. Edit the same message again, change the text again and save. Verify the file still shows as a card.
  5. Edit it once more and add text above and below the file. Verify neither text line overlaps the card.
  6. Send merchant_rules_import_mock.csv on its own with no text. Wait for the upload to finish, edit the comment, rename the label to mhant_rules_import_mock.csv and save.
  7. Verify the renamed card shows the new name at full height with (edited) under it.
  8. Type some text, attach Ăn dặm.csv and send. While the file is still uploading, edit the text and save.
  9. Verify the edited text appears straight away, the file is still there, and both stay once the upload finishes.
  10. Send another text plus file. While the spinner is still showing, edit the comment, change the file name in the editor, for example to 124.csv, and save. Verify the file keeps that name once the upload finishes.
  11. Send a .csv on its own, wait for the upload, edit the label to a name without an extension such as edited per diem and save.
  12. Click the card and verify the download is saved as edited per diem-<timestamp>.csv, then right click the message, choose Download and verify it downloads under the same name instead of opening a new tab.
  13. Send an image attachment and wait for the upload. Edit that message, copy the image's full URL out of the editor and cancel the edit.
  14. Paste that URL into the composer as a message of its own and send it. Verify the URL stays visible as a clickable link rather than a card or a blank gap.
  15. Send [![photo](URL)](URL) with that same URL in both places. Verify the image is displayed and nothing is left over as raw markdown.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline, send text plus a .csv file, then edit the label and save.
  2. Verify the card shows the new name with (edited) under it while the edit is pending.
  3. Go back online and verify the card and label stay the same after the edit syncs.
  4. Go offline again, send text plus a .csv, edit the text while it is queued and save. Verify the edited text shows and the file is still there.
  5. Go back online and verify the message keeps both the edited text and the file as a card, under its own file name and not file.
  6. Repeat step 4, then fully restart the app before going back online. Verify the edit is still applied once the attachment syncs.

QA Steps

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
  • 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 the Expensify/design team so they 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

@mukhrr
mukhrr requested review from a team as code owners September 21, 2026 09:59
@melvin-bot
melvin-bot Bot requested review from brunovjk and trjExpensify and removed request for a team September 21, 2026 09:59
@melvin-bot

melvin-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

@brunovjk 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 September 21, 2026 09:59
Editing a comment that holds a file attachment now renders a card
instead of a link, but the server echo strips the attachment
attributes, so the message leaves the attachment-only render path
and the card ends up inline in a Text run. Native Text cannot lay
out a card there: it collapses, overlaps the line above, or hides
the "(edited)" label after it.

Every file anchor now gets its own block, in both the text and the
attachment render paths, and the attachment path shows the edited
label after that block, which covers the offline edit where the
optimistic html still carries the attributes.

A file name with underscores also reads as markdown emphasis when
the edit is parsed, which left the anchor with <em> children and no
label to show. The literal label is restored from the draft after
the parse, and the renderer reads the name from the anchor's full
text so already stored messages keep a name.
@mukhrr
mukhrr force-pushed the fix/99385-regressions branch from 6512c3f to f3b495a Compare September 21, 2026 10:05
@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/CONST/index.ts 95.90% <ø> (ø)
src/ONYXKEYS.ts 100.00% <ø> (ø)
...ents/HTMLEngineProvider/BaseHTMLEngineProvider.tsx 85.89% <100.00%> (+0.18%) ⬆️
...TMLEngineProvider/HTMLRenderers/AnchorRenderer.tsx 82.35% <100.00%> (+8.82%) ⬆️
src/libs/AttachmentAnchorUtils.ts 100.00% <100.00%> (ø)
src/libs/ExportOnyxState/masking.ts 80.95% <ø> (ø)
src/libs/fileDownload/FileUtils.ts 52.59% <100.00%> (+5.33%) ⬆️
src/libs/prepareRequestPayload/index.native.ts 81.13% <100.00%> (+13.82%) ⬆️
...es/inbox/report/ContextMenu/ContextMenuActions.tsx 44.66% <100.00%> (+0.23%) ⬆️
...rc/pages/inbox/report/ReportActionItemFragment.tsx 66.03% <100.00%> (+10.26%) ⬆️
... and 9 more
... and 725 files with indirect coverage changes

Render tests drive an edited file attachment through ReportActionItem
for the text path, the attachment path with its edited label, an
emphasis-wrapped label and text on both sides of the file. An action
test checks that editReportComment queues the literal label when it
would otherwise parse as emphasis.
The server re-serializes an edited comment without the source
attribute, so an attachment-only message stopped counting as one
after any edit and the LHN row showed the file name instead of
"[Attachment]". The attachment ID survives the round trip and now
identifies a file anchor as well. A pasted link to an attachment
URL carries neither attribute and stays an ordinary message.
…at list

The chat row text is the parser's html-to-text of the action html, and the
parser only turns an anchor into [Attachment] while it still carries
data-expensify-source. The server drops that attribute on edit, so a
text-plus-file message showed the file name in the row after a rename.
File anchors are now replaced with the attachment token before the parser
runs, using the same anchor test as the render path.
@brunovjk

brunovjk commented Sep 21, 2026 •

Copy link
Copy Markdown

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
101717_android_native.mov
Android: mWeb Chrome
101717_android_web.mov
iOS: HybridApp
101717_ios_native.mov
iOS: mWeb Safari
101717_ios_web.mov
MacOS: Chrome / Safari
101717_web_chrome.mov

trjExpensify
trjExpensify previously approved these changes Sep 21, 2026

@trjExpensify trjExpensify left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

deploy blocker fixes. 👍

@brunovjk

Copy link
Copy Markdown

@mukhrr I can still reproduce something similar to 101692:

  • While offline, edit the text along with the attachment.
  • After coming back online, an error message appears, and later, the attachment (even with the error) disappears:
Screen.Recording.2026-09-21.at.10.57.32.mov

@github-actions

Copy link
Copy Markdown

This PR adds a new Onyx.connectWithoutView call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @luacmartins, @chuckdries) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the @frontend-performance team approved using connectWithoutView here.

A file queued while offline is read back as a React Native File before it
is appended to the request. That File keeps its name and type on the
prototype, and the multipart part is built from the object's own
properties, so the part went out without a filename and the server stored
the attachment as "file". The name and type are now own properties of the
file that is appended.
@mukhrr

mukhrr commented Sep 22, 2026

Copy link
Copy Markdown
Author

@brunovjk I think we are good to move here

@brunovjk

Copy link
Copy Markdown

We have some conflicts, @mukhrr. I’ll review this PR at the end of the day or tomorrow morning at the latest, if it's OK. I have some other PRs to check. Thanks.

@mukhrr

mukhrr commented Sep 22, 2026

Copy link
Copy Markdown
Author

no problem. will resolve conflicts later. It's on tests, so i guess it doesn't prevent from reviewing. thanks

@mukhrr
mukhrr dismissed stale reviews from lakchote and luacmartins via aee5572 October 21, 2026 04:48
@github-actions
github-actions Bot requested a review from chuckdries October 21, 2026 04:48
@github-actions

Copy link
Copy Markdown

This PR adds a new Onyx.connectWithoutView call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @luacmartins, @chuckdries) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the @frontend-performance team approved using connectWithoutView here.

@mukhrr
mukhrr requested a review from lakchote October 21, 2026 04:53
@mountiny
mountiny removed their request for review October 21, 2026 10:24
@chuckdries
chuckdries removed their request for review October 21, 2026 14:41
luacmartins
luacmartins previously approved these changes Oct 21, 2026
@github-actions

Copy link
Copy Markdown

This PR adds a new Onyx.connectWithoutView call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @luacmartins, @chuckdries) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the @frontend-performance team approved using connectWithoutView here.

@mukhrr
mukhrr requested a review from lakchote October 22, 2026 15:18
@chuckdries
chuckdries removed their request for review October 22, 2026 15:25
@mukhrr

mukhrr commented Oct 22, 2026

Copy link
Copy Markdown
Author

@luacmartins thanks for the 3rd approval 😅

@lakchote lakchote left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the quick fix, LGTM.

@lakchote
lakchote merged commit b4c0ec8 into Expensify:main Oct 23, 2026
36 of 37 checks passed
@OSBotify

Copy link
Copy Markdown

✋ 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

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

@OSBotify

Copy link
Copy Markdown

🚀 Deployed to staging by https://github.com/lakchote in version: 9.5.20-0 🚀

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

@MelvinBot

Copy link
Copy Markdown

No help site update needed. This PR fixes a bug so edited comments keep their file attachments, which is what users already expect, and Chat Features and Moderation Tools already describes this behavior correctly.


view run

@OSBotify

Copy link
Copy Markdown

🚀 Deployed to production by https://github.com/jasperhuangg in version: 9.5.20-5 🚀

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

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.

8 participants