Skip to content

The agent that grows with you

fix(desktop): clear edit-composer submitting latch after 200ms cooldown

xrwang847970a9e4cbd
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
index 901cf1dc724..5153898e93b 100644
--- a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
@@ -105,6 +105,7 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
// key so the matching keyup skips refreshTrigger (timing-immune vs reading
// `trigger`, which keyup sees as already-null after Escape).
const triggerKeyConsumedRef = useRef(false)
+ const composingRef = useRef(false) // true during IME composition (CJK input)
const [triggerPlacement, setTriggerPlacement] = useState<'bottom' | 'top'>('top')
const [focusRequestId, setFocusRequestId] = useState(0)
const [submitting, setSubmitting] = useState(false)
@@ -598,6 +599,13 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
// hazard on the main composer).
try {
aui.composer().send()
+
+ // Clear latch after cooldown to allow re-submission. This prevents rapid
+ // double-Enter but doesn't require tracking when onEdit settles (which may
+ // be synchronous or async, and whose promise we don't have access to).
+ window.setTimeout(() => {
+ setSubmitting(false)
+ }, 200)
} catch {
setSubmitting(false)
}
@@ -657,6 +665,7 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
composingRef.current = false
}
+ // IME composition: Enter confirms composed text, not a message submission.
if (composingRef.current || event.nativeEvent.isComposing) {
return
}
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-message-edit.test.tsx b/apps/desktop/src/components/assistant-ui/thread/user-message-edit.test.tsx
index dfd1a78c509..07e0bf13528 100644
--- a/apps/desktop/src/components/assistant-ui/thread/user-message-edit.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/user-message-edit.test.tsx
@@ -237,3 +237,79 @@ describe('click-to-edit user message', () => {
expect(editor.className).toContain('overflow-y-auto')
})
})
+
+describe('Enter submission and latch behavior', () => {
+ it('submits the edit when Enter is pressed', async () => {
+ const onEdit = vi.fn(async () => {})
+ render(<IncrementalHarness onEdit={onEdit} />)
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
+
+ const editor = await screen.findByRole('textbox', { name: 'Edit message' })
+ const editedText = 'modified text for submission'
+
+ editor.textContent = editedText
+ fireEvent.input(editor)
+
+ fireEvent.keyDown(editor, { key: 'Enter' })
+
+ await waitFor(() => {
+ expect(onEdit).toHaveBeenCalledTimes(1)
+ })
+ })
+
+ it('clears the submitting latch after onEdit resolves, allowing second edit session', async () => {
+ const onEdit = vi.fn(async () => {})
+ render(<IncrementalHarness onEdit={onEdit} />)
+
+ // First edit session
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
+
+ let editor = await screen.findByRole('textbox', { name: 'Edit message' })
+ editor.textContent = 'first edit'
+ fireEvent.input(editor)
+ fireEvent.keyDown(editor, { key: 'Enter' })
+
+ await waitFor(() => {
+ expect(onEdit).toHaveBeenCalledTimes(1)
+ })
+
+ // Wait for the latch cooldown to clear
+ await new Promise(resolve => setTimeout(resolve, 300))
+
+ // Second edit session - open the editor again
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
+
+ editor = await screen.findByRole('textbox', { name: 'Edit message' })
+ editor.textContent = 'second edit'
+ fireEvent.input(editor)
+ fireEvent.keyDown(editor, { key: 'Enter' })
+
+ // If the latch wasn't cleared, this second submission would be blocked
+ await waitFor(() => {
+ expect(onEdit).toHaveBeenCalledTimes(2)
+ })
+ })
+
+ it('inserts a newline on Shift+Enter without submitting', async () => {
+ const onEdit = vi.fn(async () => {})
+ render(<IncrementalHarness onEdit={onEdit} />)
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
+
+ const editor = await screen.findByRole('textbox', { name: 'Edit message' })
+
+ editor.textContent = 'line one'
+ fireEvent.input(editor)
+
+ fireEvent.keyDown(editor, { key: 'Enter', shiftKey: true })
+
+ // Shift+Enter should not call onEdit
+ await new Promise(resolve => window.setTimeout(resolve, 50))
+ expect(onEdit).not.toHaveBeenCalled()
+
+ // The editor should allow the newline to be inserted (by not preventing default)
+ // We don't simulate actual newline insertion here (requires complex DOM manipulation)
+ // but we verify the guard did not block it
+ })
+})