Repository navigation
Keep a file attachment intact when its comment is edited - #99385
Conversation
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 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.
|
# Conflicts: # src/libs/ReportUtils.ts # tests/unit/ReportUtilsTest.ts
|
This PR adds a new |
There was a problem hiding this comment.
💡 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".
| if (uploadingAttachmentHtml && !hasQueuedAttachmentRequest) { | ||
| Onyx.update(optimisticData); | ||
| deferEditUntilAttachmentSyncs(originalReport, reportActionID, textForNewComment, isOriginalReportArchived, currentUserLogin, personalDetails, videoAttributeCache, () => { |
There was a problem hiding this comment.
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 👍 / 👎.
| 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; |
There was a problem hiding this comment.
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 👍 / 👎.
|
@brunovjk i think we are good to move here, just fyi, we are fixing 4 bugs here
|
# Conflicts: # src/libs/fileDownload/FileUtils.ts
|
This PR adds a new |
|
resolved |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 chuckdries has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/chuckdries in version: 9.4.90-0 🚀
|
|
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 ( 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:
Label verification. Add attachment was confirmed against the live web UI (composer One thing I could not do: GitHub rejected assigning you to the docs PR — Scope note: I left the article's pre-existing multiple @mukhrr, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR |
|
Deploy Blocker #101689 was identified to be related to this PR. |
|
Deploy Blocker #101692 was identified to be related to this PR. |
|
Deploy Blocker #101693 was identified to be related to this PR. |
|
This PR failing in offline mode because of the issue #101744 Bug7265022_1789972037997.az_recorder_20260921_130709.1.mp4 |
|
🚀 Deployed to production by https://github.com/lakchote in version: 9.4.90-2 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Editing a comment that holds a file attachment broke in four places:
AnchorRendereralso recognises the attachment by its URL, since the server returns edited comments stripped.Fixed Issues
$ #98743
PROPOSAL: #98743 (comment)
Tests
.csvor.docfile and click Send.124.csv, then save..csvfile on its own and wait for the upload to finish. Edit the comment and change the label to a name without an extension, for exampleedited per diem, then save and wait a few seconds.edited per diem-<timestamp>.csv, not without an extension and not under the random hashed name.Offline tests
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari