Skip to content

Keep a file attachment intact when its comment is edited - #99385

Merged
chuckdries merged 16 commits into
Expensify:mainfrom
mukhrr:fix/98743
Sep 18, 2026
Merged

chuckdries merged 16 commits into
Expensify:mainfrom
mukhrr:fix/98743

Conversation

@mukhrr

@mukhrr mukhrr commented Aug 25, 2026 •

Copy link
Copy Markdown

Explanation of Change

Editing a comment that holds a file attachment broke in four places:

  1. The edit dropped the attachment attributes, so the file rendered as a plain link. They are restored on the way out, and AnchorRenderer also recognises the attachment by its URL, since the server returns edited comments stripped.
  2. An edit saved while the upload was still in flight sent the text alone and the file disappeared. The edit is now stored in Onyx and replayed once the attachment syncs, so it survives a restart, and a newer edit or a delete cancels it.
  3. Downloading a renamed attachment lost the file extension, and the context menu Download opened the chat URL once the source attribute was gone ([Due for payment 2026-11-02] [Exploratory] Chat - Doc file border and download icon missing after edit comment. #98743 (comment)). The download name now takes the extension from the stored file, and the source falls back to the anchor href, only for Expensify-hosted URLs.
  4. A file renamed while still uploading reverted to its original name. The new name now travels with the queued file.

Fixed Issues

$ #98743
PROPOSAL: #98743 (comment)

Tests

  1. Open any chat.
  2. Type some text in the composer, then click the plus, choose Add attachment, pick a .csv or .doc file and click Send.
  3. Wait for the upload to finish.
  4. Right click the message, choose Edit comment, change the text and save.
  5. Verify the file still shows inside a bordered card with a download icon, and is not a plain blue link.
  6. Edit the same message again, change the text again and save.
  7. Verify the file still shows as a file, so a second edit does not degrade it.
  8. Send another message with text and a file. While the attachment is still showing its spinner, right click it, choose Edit comment, change the text and save.
  9. Verify the edited text appears straight away and the file is still there.
  10. Wait for the upload to finish and verify both the edited text and the file are still there.
  11. Send one more message with text and a file. While the spinner is still showing, edit the comment and change the file name in the editor, for example to 124.csv, then save.
  12. Wait for the upload to finish and verify the file keeps the name you gave it.
  13. Send a .csv file on its own and wait for the upload to finish. Edit the comment and change the label to a name without an extension, for example edited per diem, then save and wait a few seconds.
  14. Click the file card and verify the download is saved as edited per diem-<timestamp>.csv, not without an extension and not under the random hashed name.
  15. Right click the same message, choose Download and verify it downloads under the same name instead of opening a new tab.
  16. Send a message with text that contains a link plus a file, edit its text and save, then right click it and choose Download. Verify the attachment downloads, not the link.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline.
  2. Type some text, attach a file and send it.
  3. While it is queued, right click the message, choose Edit comment, change the text and save.
  4. Verify the edited text shows and the file is still there.
  5. Go back online.
  6. Verify the message keeps both the edited text and the file, and the file shows as a file rather than a link.

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

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

mukhrr added 5 commits August 24, 2026 17:59
The markdown round-trip an edit goes through preserves attributes for
images and videos, because the parser caches them, but it has no such
handling for anchors. A doc attachment therefore came back as an
ordinary link, losing its border and download icon, and losing the auth
token its download needs.

Re-apply the dropped attributes to anchors whose href matches an
attachment in the original comment.
The server strips the source attribute from its UpdateComment response but keeps the attachment ID.
Match on either one so a second edit still recognises the anchor, and treat the ID as an attachment
marker when rendering, so the border and download icon survive the round trip.
Renaming a still-uploading attachment while editing only held until the send went through, because the
server rebuilds the stored attachment from the uploaded file. Carry the new label on the queued file as
well as the optimistic markup so it survives the sync.
The server returns edited comments with the attachment attributes stripped from the anchor, leaving nothing
to tell an attachment apart from an ordinary link. Fall back to the URL, the way ImageRenderer already does.
The upload leaves the request queue before it completes, so an edit saved during that window had nothing left
to carry the file and replaced the comment with its text alone. Hold the edit until the attachment syncs, then
send it against the stored copy, keeping any name the author gave the file while it was uploading.
@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/ONYXKEYS.ts 100.00% <ø> (ø)
...TMLEngineProvider/HTMLRenderers/AnchorRenderer.tsx 73.91% <100.00%> (+0.38%) ⬆️
src/libs/ExportOnyxState/common.ts 80.95% <ø> (ø)
src/libs/fileDownload/FileUtils.ts 44.98% <100.00%> (+0.64%) ⬆️
src/libs/fileDownload/getAttachmentDetails.ts 100.00% <100.00%> (ø)
...orAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx 0.00% <0.00%> (ø)
src/libs/actions/Report/index.ts 72.11% <95.45%> (+0.43%) ⬆️
src/libs/actions/RequestConflictUtils.ts 99.13% <87.50%> (-0.87%) ⬇️
src/libs/ReportUtils.ts 87.40% <95.00%> (+0.05%) ⬆️
...es/inbox/report/ContextMenu/ContextMenuActions.tsx 40.33% <0.00%> (-0.06%) ⬇️
... and 1 more
... and 12 files with indirect coverage changes

@mukhrr mukhrr changed the title Keep a file attachment intact when its comment is edited 'Keep a file attachment intact when its comment is edited Sep 8, 2026
@mukhrr mukhrr changed the title 'Keep a file attachment intact when its comment is edited [HOLD] Keep a file attachment intact when its comment is edited Sep 8, 2026
@mukhrr mukhrr changed the title [HOLD] Keep a file attachment intact when its comment is edited Keep a file attachment intact when its comment is edited Sep 11, 2026
@mukhrr
mukhrr marked this pull request as ready for review September 11, 2026 09:01
@mukhrr
mukhrr requested review from a team as code owners September 11, 2026 09:01
@melvin-bot
melvin-bot Bot requested review from brunovjk and heyjennahay and removed request for a team September 11, 2026 09:01
@melvin-bot

melvin-bot Bot commented Sep 11, 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 11, 2026 09:01
@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) — 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: effda70993

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/actions/Report/index.ts Outdated
Comment on lines +3838 to +3840
if (uploadingAttachmentHtml && !hasQueuedAttachmentRequest) {
Onyx.update(optimisticData);
deferEditUntilAttachmentSyncs(originalReport, reportActionID, textForNewComment, isOriginalReportArchived, currentUserLogin, personalDetails, videoAttributeCache, () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Cancel stale deferred edits before removing an attachment

When a user first edits an in-flight attachment while keeping it, then edits again and removes it, uploadingAttachmentHtml becomes undefined so this branch is skipped without cancelling the existing deferredAttachmentEdits entry. The removal's optimistic Onyx update then looks like a completed upload to the old subscriber because the optimistic-source attribute is gone, causing it to replay the stale first draft and potentially restore the attachment or overwrite the newer text. Cancel any existing deferred edit whenever a newer edit is submitted, including the attachment-removal path.

Useful? React with 👍 / 👎.

Comment on lines +3838 to +3843
if (uploadingAttachmentHtml && !hasQueuedAttachmentRequest) {
Onyx.update(optimisticData);
deferEditUntilAttachmentSyncs(originalReport, reportActionID, textForNewComment, isOriginalReportArchived, currentUserLogin, personalDetails, videoAttributeCache, () => {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, {[reportActionID]: {...originalReportAction, pendingAction: null}});
});
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Persist deferred attachment edits across restarts

When the attachment request is already in flight, this path writes only optimistic Onyx data and returns without persisting an UpdateComment request; the actual edit exists solely in the module-local callback map. If the mobile app is killed or the page reloads before the upload completes, that callback disappears while the upload request is recovered and retried, so the server never receives the user's edit and a later sync can replace it with the original comment. Store a replayable queued request or otherwise reconstruct these deferred edits at startup to preserve the repository's offline-first, queue-based behavior. CLAUDE.mdL82-L87

Useful? React with 👍 / 👎.

@mukhrr

mukhrr commented Sep 11, 2026 •

Copy link
Copy Markdown
Author

@brunovjk i think we are good to move here, just fyi, we are fixing 4 bugs here

1 The edit dropped the attachment attributes, so the file rendered as a plain link. They are restored on the way out, and AnchorRenderer also recognises the attachment by its URL, since the server returns edited comments stripped.
2 An edit saved while the upload was still in flight sent the text alone and the file disappeared. The edit is now stored in Onyx and replayed once the attachment syncs, so it survives a restart, and a newer edit or a delete cancels it.
3 Downloading a renamed attachment lost the file extension, and the context menu Download opened the chat URL once the source attribute was gone ([Exploratory] Chat - Doc file border and download icon missing after edit comment. #98743 (comment)). The download name now takes the extension from the stored file, and the source falls back to the anchor href, only for Expensify-hosted URLs.
4 A file renamed while still uploading reverted to its original name. The new name now travels with the queued file.

# Conflicts:
#	src/libs/fileDownload/FileUtils.ts
@mukhrr
mukhrr dismissed stale reviews from chuckdries and tgolen via 554fff5 September 18, 2026 04:52
@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 commented Sep 18, 2026

Copy link
Copy Markdown
Author

resolved

@mountiny
mountiny removed their request for review September 18, 2026 10:08
@chuckdries
chuckdries merged commit bf8db60 into Expensify:main Sep 18, 2026
37 of 38 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

🚧 chuckdries 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/chuckdries in version: 9.4.90-0 🚀

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

@MelvinBot

Copy link
Copy Markdown

Yes — help site changes are needed, and I opened a draft PR for them: Docs updates for E/A#99385 attachment behavior when editing chat comments (Expensify/App#101640).

Why a change is needed. Strictly, this PR restores intended behavior rather than adding a feature, so nothing on the help site became wrong. But it did expose a real gap: docs/articles/new-expensify/chat/Chat-Features-and-Moderation-Tools.md documents how to Add attachment but never how to download one, and its "Edit or Delete Messages" section says nothing about what happens to an attached file when you edit the message. Both are exactly what this PR changed.

What the docs PR adds:

  • A ## How to download a file attachment from a chat message section, with web and mobile steps, plus the download file-name behavior (the original extension is added back when the displayed name leaves it off).
  • A note under "Edit or Delete Messages": editing changes only the message text, and the file stays attached — including when you edit mid-upload.
  • Two FAQ entries — whether an attachment survives an edit, and how to rename one.
  • The required internalScope metadata field, and updated description / keywords.

Label verification. Add attachment was confirmed against the live web UI (composer + menu, alongside Create expense, Track distance, and Assign task). Edit comment and Download were confirmed against src/languages/en.ts — common.download and reportActionContextMenu.editAction. I could not drive the attachment upload or the message context menu in the live browser session (the file picker and right-click are outside what the web test harness can reach), so those two labels come from the language file rather than a screenshot.

One thing I could not do: GitHub rejected assigning you to the docs PR — mukhrr currently has read permission on Expensify/App, and GitHub only allows assignees with write access or prior participation on the item. The HelpDot label is applied and Expensify/pullerbear is requested as reviewer. Once you comment on #101640, assignment should work; I'd suggest self-assigning there.

Scope note: I left the article's pre-existing multiple # headings alone. They don't comply with the current HELP_AUTHORING_GUIDELINES.md single-# rule, but restructuring that legacy article is a separate change from documenting this fix.

@mukhrr, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@jponikarchuk

Copy link
Copy Markdown

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

@jponikarchuk

Copy link
Copy Markdown

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

@jponikarchuk

Copy link
Copy Markdown

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

@jponikarchuk

Copy link
Copy Markdown

This PR failing in offline mode because of the issue #101744
This issue is reproducible in: Android and iOS app

Bug7265022_1789972037997.az_recorder_20260921_130709.1.mp4

@OSBotify

Copy link
Copy Markdown

🚀 Deployed to production by https://github.com/lakchote in version: 9.4.90-2 🚀

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.

9 participants