Skip to content

fix: Downscale large images before attaching#1987

Merged
charlesvien merged 9 commits intomainfrom
05-02-downscale_large_images_before_attaching
May 4, 2026
Merged

fix: Downscale large images before attaching#1987
charlesvien merged 9 commits intomainfrom
05-02-downscale_large_images_before_attaching

Conversation

@charlesvien
Copy link
Copy Markdown
Member

@charlesvien charlesvien commented May 3, 2026

Problem

Large images (>2000px) fail with a dimension limit error when attached via file picker or drag-and-drop. Cmd+V paste already worked because it pre-downscales through ElectronImageProcessor.

Closes #1889

Changes

  1. Add downscaleImageFile tRPC endpoint that reads an on-disk image and downscales via existing ElectronImageProcessor
  2. Extract shared downscaleAndPersist helper to deduplicate saveClipboardImage and the new endpoint
  3. Route image files in all attachment paths through the downscale pipeline
  4. Extract resolveDroppedFile utility to deduplicate drop handler logic across components

How did you test this?

Manually

@charlesvien charlesvien force-pushed the 05-02-downscale_large_images_before_attaching branch 2 times, most recently from 343dd63 to fa4664e Compare May 3, 2026 08:53
@charlesvien charlesvien force-pushed the 05-02-show_pr_and_diff_status_icons_on_task_list_items branch from 8d7c1d1 to d085988 Compare May 3, 2026 08:53
@charlesvien charlesvien marked this pull request as ready for review May 3, 2026 17:55
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 3, 2026

Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
apps/code/src/renderer/features/sessions/components/SessionView.tsx:375-382
**Duplicate drop-handler logic (OnceAndOnlyOnce)**

The async drop-handling loop in `SessionView.tsx` and `TaskInput.tsx` (lines 548–555) is now character-for-character identical. The PR already introduced `resolveDroppedFile` to deduplicate `useTiptapEditor` and the two component drop handlers — this same pattern of iterating files and calling `editorRef.current?.addAttachment` appears verbatim in both components and could be extracted into a shared helper (e.g. `resolveAndAttachDroppedFiles(files, addAttachment)`) to stay consistent with the existing deduplication work.

### Issue 2 of 3
apps/code/src/renderer/features/message-editor/utils/persistFile.ts:71-86
**Inconsistent error handling across drop paths**

When `persistImageFilePath` throws (e.g. image is >50MB or the processor fails), `resolveDroppedFile` silently falls back to the original un-downscaled file path. In `AttachmentMenu.tsx` the same failure surfaces a `toast.error("Failed to attach image")`. For the drop paths in `useTiptapEditor`, `SessionView`, and `TaskInput`, the user gets no feedback that downscaling was skipped and the image may still exceed the upstream dimension limit. At a minimum a toast on the catch branch would align the two paths.

### Issue 3 of 3
apps/code/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts:370-388
**Drop handler now always consumes the event**

`event.preventDefault()` and `return true` are now unconditional. Previously, if every dropped file had no resolvable path (`getFilePath` returns `""`), the handler returned `false`, letting tiptap or the browser handle the drop normally. After this change, any file drop is always swallowed — including cases where all `resolveDroppedFile` calls return `null` — which could silently discard drops of items that don't have an Electron file path attached. This is a minor but real behaviour change worth documenting or guarding.

Reviews (1): Last reviewed commit: "Consolidate image constants and unify dr..." | Re-trigger Greptile

Comment thread apps/code/src/renderer/features/sessions/components/SessionView.tsx Outdated
Comment thread apps/code/src/renderer/features/message-editor/utils/persistFile.ts
@charlesvien charlesvien force-pushed the 05-02-show_pr_and_diff_status_icons_on_task_list_items branch from d085988 to ab33331 Compare May 3, 2026 23:13
@charlesvien charlesvien force-pushed the 05-02-downscale_large_images_before_attaching branch from fa4664e to 00b5fb3 Compare May 3, 2026 23:13
@charlesvien charlesvien force-pushed the 05-02-show_pr_and_diff_status_icons_on_task_list_items branch from ab33331 to 6310a52 Compare May 4, 2026 01:38
@charlesvien charlesvien force-pushed the 05-02-downscale_large_images_before_attaching branch 2 times, most recently from c62d6b9 to 6a11acc Compare May 4, 2026 05:10
Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab left a comment

Choose a reason for hiding this comment

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

nice one

@charlesvien charlesvien force-pushed the 05-02-downscale_large_images_before_attaching branch 3 times, most recently from 30015b0 to fa56f04 Compare May 4, 2026 14:39
@charlesvien charlesvien force-pushed the 05-02-show_pr_and_diff_status_icons_on_task_list_items branch 2 times, most recently from 2f8d1ae to 9d74bcd Compare May 4, 2026 18:38
@charlesvien charlesvien force-pushed the 05-02-downscale_large_images_before_attaching branch from b77e0c7 to dd6be59 Compare May 4, 2026 18:38
@charlesvien charlesvien added the Create release This will trigger a new release label May 4, 2026 — with Graphite App
@charlesvien charlesvien changed the base branch from 05-02-show_pr_and_diff_status_icons_on_task_list_items to graphite-base/1987 May 4, 2026 19:06
@charlesvien charlesvien force-pushed the 05-02-downscale_large_images_before_attaching branch from dd6be59 to bd286e7 Compare May 4, 2026 19:06
@charlesvien charlesvien force-pushed the graphite-base/1987 branch from 9d74bcd to 0587776 Compare May 4, 2026 19:06
@graphite-app graphite-app Bot changed the base branch from graphite-base/1987 to main May 4, 2026 19:06
@charlesvien charlesvien force-pushed the 05-02-downscale_large_images_before_attaching branch from bd286e7 to 813e5c9 Compare May 4, 2026 19:07
@charlesvien charlesvien merged commit 53cc2db into main May 4, 2026
16 checks passed
Copy link
Copy Markdown
Member Author

Merge activity

@charlesvien charlesvien deleted the 05-02-downscale_large_images_before_attaching branch May 4, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Create release This will trigger a new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large images fail to be read when attached via drag-and-drop or file picker (but work with Cmd+V paste)

2 participants