fix: prevent Enter from sending message during IME composition

Check e.nativeEvent.isComposing and keyCode 229 in addition to
React state, fixing a race condition where compositionend fires
before keydown on some browsers (Chrome/macOS).

Fixes #20
This commit is contained in:
Nicolas Varrot
2026-03-09 21:01:33 +00:00
parent a129d22007
commit e223804777

View File

@@ -209,7 +209,9 @@ export function ChatInput({ onSend, onNewSession, onAbort, isGenerating, disable
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
// Prevent sending when IME is composing (e.g., Chinese/Japanese input)
if (isComposing) return;
// Check both React state and native event property — on some browsers
// compositionend fires before keydown, making isComposing stale
if (isComposing || e.nativeEvent.isComposing || e.keyCode === 229) return;
if (sendOnEnter) {
// Enter sends, Shift+Enter for newline
if (!e.shiftKey && !e.ctrlKey && !e.metaKey) {