Repository navigation
fix(native-chat): keep every image chip when several images are dropped at once - #32022
Conversation
Each chip's node view renders the composer inside the editor's change, before the editor reports it, so the draft sync wrote the older draft back over it.
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a91b2c91-3b32-45ec-8c97-6112bd901eec
📒 Files selected for processing: 2
src/renderer/src/components/native-chat/NativeChatComposerField.tsxsrc/renderer/src/components/native-chat/native-chat-composer-ime-file-drop.test.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| if (draft !== editorDraftRef.current && textarea.value !== draft) { | ||
| textarea.value = draft | ||
| } | ||
| textarea.value = draft | ||
| editorDraftRef.current = draft |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n "settleImeValue|imeComposedSegment|onImeSettled|isComposing|composition" src/renderer/src/components/native-chat/NativeChatComposerField.tsx src/renderer/src/components/native-chat/NativeChatComposer.tsx src/renderer/src/components/native-chat src/renderer/src -g '*.tsx' -g '*.ts' | head -240
sed -n '1,180p' src/renderer/src/components/native-chat/use-native-chat-ime-enter-gesture.ts 2>/dev/null || trueRepository: stablyai/orca
Length of output: 32818
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- NativeChatComposerField.tsx ---'
nl -ba src/renderer/src/components/native-chat/NativeChatComposerField.tsx | sed -n '90,235p'
nl -ba src/renderer/src/components/native-chat/NativeChatComposerField.tsx | sed -n '280,345p'
printf '%s\n' '--- NativeChatComposer.tsx parent settlement and field ---'
nl -ba src/renderer/src/components/native-chat/NativeChatComposer.tsx | sed -n '360,420p'
nl -ba src/renderer/src/components/native-chat/NativeChatComposer.tsx | sed -n '70,115p'
printf '%s\n' '--- draft/picker/send related source ---'
nl -ba src/renderer/src/components/native-chat/use-native-chat-draft.ts | sed -n '1,90p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-picker-state.ts | sed -n '145,195p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.ts | sed -n '105,145p'
printf '%s\n' '--- relevant tests ---'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-composition.test.tsx | sed -n '80,330p'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx | sed -n '1,230p'
printf '%s\n' '--- PR diff for field and related tests ---'
git diff --unified=80 d053ff97ab3613a3813eb76604de1435f02607ae 7ad600519138a3fe18a59eaf8cfc5282d9ab0d42 -- src/renderer/src/components/native-chat/NativeChatComposerField.tsx src/renderer/src/components/native-chat/NativeChatComposer.tsx src/renderer/src/components/native-chat/native-chat-composer-composition.test.tsx src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsxRepository: stablyai/orca
Length of output: 42231
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- NativeChatComposer draft handlers and editor wiring ---'
rg -n -F -- 'handleDraftChange' src/renderer/src/components/native-chat/NativeChatComposer.tsx
rg -n -F -- 'NativeChatPromptEditor' src/renderer/src/components/native-chat src/renderer/src -g '*.tsx' -g '*.ts' | head -80
nl -ba src/renderer/src/components/native-chat/NativeChatComposer.tsx | sed -n '115,230p'
nl -ba src/renderer/src/components/native-chat/NativeChatComposer.tsx | sed -n '230,360p'
printf '%s\n' '--- Prompt editor implementation ---'
rg -n -F -- 'export function NativeChatPromptEditor' src/renderer/src
rg -n -F -- 'onChange' src/renderer/src/components/native-chat/NativeChatPromptEditor.tsx src/renderer/src/components/native-chat/native-chat-prompt-editor-store-value.test.tsx 2>/dev/null || true
nl -ba src/renderer/src/components/native-chat/NativeChatPromptEditor.tsx | sed -n '1,240p' 2>/dev/null || true
printf '%s\n' '--- complete composition tests around direct settlement and external changes ---'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-composition.test.tsx | sed -n '88,335p'
printf '%s\n' '--- external draft write/call sites relevant to recall, picker, send clear ---'
rg -n -F -- 'setDraft(' src/renderer/src/components/native-chat -g '*.tsx' -g '*.ts' | grep -E 'recall|picker|structured|send|NativeChatComposer|setDraft' | head -180
rg -n -F -e 'handleDraftOrCaretChange' -e 'commitCompletion' -e 'setDraft(' src/renderer/src/components/native-chat/use-native-chat-composer-recall.ts src/renderer/src/components/native-chat/use-native-chat-picker-state.ts src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.ts src/renderer/src/components/native-chat/NativeChatComposer.tsx 2>/dev/null || trueRepository: stablyai/orca
Length of output: 42182
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- IME ownership implementation ---'
rg -n -F -- 'useImeEnterGestureOwnership' src/renderer/src
nl -ba src/renderer/src/lib/ime-composition-keyboard-event.ts | sed -n '1,240p' 2>/dev/null || true
printf '%s\n' '--- NativeChatPromptEditor update and value setter ---'
nl -ba src/renderer/src/components/native-chat/NativeChatPromptEditor.tsx | sed -n '90,220p'
printf '%s\n' '--- structured send clear path ---'
nl -ba src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.ts | sed -n '105,140p'
printf '%s\n' '--- recall implementation and invocation ---'
rg -n -F -- 'useNativeChatComposerRecall' src/renderer/src/components/native-chat
nl -ba src/renderer/src/components/native-chat/use-native-chat-composer-recall.ts | sed -n '1,240p' 2>/dev/null || true
nl -ba src/renderer/src/components/native-chat/use-native-chat-composer-keydown.ts | sed -n '120,190p'
printf '%s\n' '--- settlement-related tests with cancellation/no-op composition ---'
rg -n -F -e 'cancel' -e 'compositionEnd' src/renderer/src/components/native-chat/native-chat-composer-ime-file-drop.test.tsx src/renderer/src/components/native-chat/native-chat-composer-composition.test.tsxRepository: stablyai/orca
Length of output: 26194
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- draft-only external writers ---'
nl -ba src/renderer/src/components/native-chat/use-native-chat-typed-insertion.ts | sed -n '1,90p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-launch-draft-adoption.ts | sed -n '80,145p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-picker-state.ts | sed -n '164,225p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-picker-command-dispatch.ts | sed -n '70,115p'
printf '%s\n' '--- shared draft store update semantics ---'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-store.ts | sed -n '1,220p'
nl -ba src/renderer/src/components/native-chat/native-chat-draft-cache.ts | sed -n '1,150p'
printf '%s\n' '--- tests with multiple composers or external draft propagation ---'
rg -n -F -e 'same scope' -e 'other composer' -e 'second' -e 'setDraft(' src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx | head -100
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx | sed -n '230,430p'Repository: stablyai/orca
Length of output: 36707
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- settlement cleanup behavior ---'
rg -n -F -- 'flushPendingAttachments' src/renderer/src/components/native-chat
rg -n -F -- 'flushDraftAppends' src/renderer/src/components/native-chat
nl -ba src/renderer/src/components/native-chat/use-native-chat-composer-attachments.ts | sed -n '180,255p'
printf '%s\n' '--- same-scope draft propagation contract/test ---'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-store.ts | sed -n '90,105p'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx | sed -n '362,395p'Repository: stablyai/orca
Length of output: 10628
Update editorDraftRef after the settlement write.
When a structured send clears the draft during an active IME composition, a canceled composition can settle with no composed segment. settleImeValue then writes '', but NativeChatPromptEditor suppresses onUpdate, so editorDraftRef still contains the previous text. onImeSettled skips handleDraftChange because the settled value already equals the cleared draft.
A later draft-only update to that previous text can then satisfy draft === editorDraftRef.current while the editor is empty. The new guard skips the synchronization and leaves the editor out of sync with the draft.
Suggested fix
element.value = imeComposedSegment(compositionBaseRef.current, element.value)
+ editorDraftRef.current = element.value
ELI5
If you dropped three images into a chat at once, all three thumbnails showed up but the prompt only got chips for #1 and #3. The middle one was erased right after it was added. Now every image you drop or paste together gets its own chip, numbered 1, 2, 3.
What Changed
The bug hit structured chats (OpenCode, OMP, Claude) whenever several images are attached in one go: a Finder/Explorer drop, or pasting several copied files. Every other chip went missing (#1, #3, #5…). Sending then gave the agent
[Image #1]and[Image #3], though all the files were attached. Adding images one at a time worked.Cause: each chip goes into the prompt editor in its own transaction. TipTap renders a chip's React node view with
flushSyncduring that transaction, before the editor reports the change. TheflushSyncalso flushes the composer's pending render. That render'sdraftis the text from before the newest chip, andNativeChatComposerField's draft→editor sync saw it differ from the editor, so it wrote the old draft back and deleted the chip it had just added.Fix: the sync remembers the draft the editor last reported or was given. A render carrying that same draft is one the editor has already moved past, so it is not pushed back. Drafts set from outside the editor (send clearing, a message handed back, recall, picker completions, appends while the editor is gone) still differ from that value and reach the editor as before. The check also skips serializing the editor's document on every keystroke.
Why
The field's sync is where the wrong fact gets written, and fixing it there covers every path that inserts more than one chip in a row: drop, multi-file paste, and anything added later. Other options were weaker:
Mobile has no inline chips in its composer, so it isn't affected. Nothing goes over the wire.
Linked Issue
Linear: STA-11357 (no GitHub issue).
The report also mentions an oversized first drop that did nothing. This branch doesn't touch that: it's a separate size/limit path, and the numbering bug reproduces without it.
Visual Proof
Hidden dev build, OpenCode chat in a folder workspace, three PNGs dropped at once with a trusted CDP drag (
Input.dispatchDragEvent).BEFORE (main): thumbnails #1–#3, chips #1 and #3
(screenshot removed: contained real product data)
AFTER (this branch): thumbnails #1–#3, chips #1, #2, #3
(screenshot removed: contained real product data)
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Reproduced on main in a hidden dev build (macOS). Dropping 3 images gave chips Linux support #1, Add Shift+Enter to insert newline in terminal #3. Dropping 5 more gave Add Ctrl+Click to open links in terminal #4, Fix MaxListenersExceededWarning with singleton PTY dispatcher #6, Fix update checker 406 error and add menu feedback #8, so every other chip was lost. With the fix: 3 → Linux support #1–Add Shift+Enter to insert newline in terminal #3, then 8 more → Linux support #1–Capitalize app name to Orca for desktop installs #11 contiguous. Typing after the drop still works.
New test in
native-chat-composer-ime-file-drop.test.tsxruns a real OS drop of three PNGs through the pane drop surface, external attachments, the draft hook and the real field and editor. It fails on main with['Image #1', 'Image #3']and passes with the fix.Focused native-chat composer, editor, IME, recall and file-drop suites (31 files, 359 tests) pass.
check:code-quality:changedandcheck:react-doctor:changedare clean.