fix(web): fall back to persisted draft bytes for transient image attachments#1836
fix(web): fall back to persisted draft bytes for transient image attachments#1836mawlicious wants to merge 2 commits intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved This is a straightforward bug fix that adds a fallback mechanism when transient blob URLs for image attachments become unreadable. The change extracts existing logic into a testable helper, adds defensive error handling that falls back to persisted draft bytes, and includes comprehensive unit tests. The scope is narrow and self-contained. You can customize Macroscope's approvability policy. Learn more. |
What Changed
Uses the persisted draft image bytes as a fallback when sending image attachments if the original
Filecan no longer be read.This fixes a case where transient attachments, like iOS Simulator screenshots dragged directly into T3 Code, can disappear before send. If the live file is still readable, the existing behavior is unchanged.
Why
iOS Simulator screenshots can be short-lived when dragged directly from the simulator preview. By the time the message is sent, the file may already be gone, which causes the attachment send to fail even though the draft already persisted the image data locally.
This change reuses that persisted draft data as a fallback instead of introducing a new cache or special-case storage path.
UI Changes
No UI changes.
Checklist
Note
Medium Risk
Changes the image-attachment send path to fall back to persisted draft data when
FileReaderfails, which could affect message sending and attachment integrity if IDs/matches are wrong. Scope is limited to web client composer attachment handling and is covered by new unit tests.Overview
Improves reliability of sending image attachments. When building turn attachments, the web client now tries to read the live
Filebytes first and, if that fails, falls back to the matching persisted draftdataUrl(by attachmentid).This factors the logic into
buildTurnImageAttachmentsand updatesChatViewsend/retry handling to snapshot and restorepersistedAttachmentsalongside images, with new tests covering live-read, fallback, and hard-failure cases.Reviewed by Cursor Bugbot for commit e33777f. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fall back to persisted draft bytes for transient image attachments on send
buildTurnImageAttachmentshelper in ChatView.logic.ts that reads live file bytes viareadFileAsDataUrl, falling back to a matching persisted attachment'sdataUrlwhen the live file is unreadable, and rejecting only if neither is available.buildTurnImageAttachmentsand snapshotpersistedAttachmentsbefore send; on send failure, syncs the snapshot back into the composer draft to restore state.Fileobject is stale or missing, as long as a persisted copy exists.Macroscope summarized e33777f.