From 585d01684abaf9c8ea656845ef81e3d2fec85be1 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Tue, 4 Aug 2026 08:53:55 -0700 Subject: [PATCH] fix(chat): preserve browser IME composition ownership --- .../native-chat/NativeChatComposerField.tsx | 57 ++++++++- .../native-chat-composer-autogrow.test.tsx | 120 +++++++++++++++++- 2 files changed, 166 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/components/native-chat/NativeChatComposerField.tsx b/src/renderer/src/components/native-chat/NativeChatComposerField.tsx index 6f954a60aa5..b255055dc9b 100644 --- a/src/renderer/src/components/native-chat/NativeChatComposerField.tsx +++ b/src/renderer/src/components/native-chat/NativeChatComposerField.tsx @@ -4,6 +4,7 @@ import type { KeyboardEventHandler, RefObject } from 'react' +import { useLayoutEffect, useRef } from 'react' import { Image as ImageIcon, ImageOff, X } from 'lucide-react' import { translate } from '@/i18n/i18n' import { cn } from '@/lib/utils' @@ -97,6 +98,17 @@ export function NativeChatComposerField({ sessionOptionsSurface, sessionOptionsSnapshot }: NativeChatComposerFieldProps): React.JSX.Element { + const compositionActiveRef = useRef(false) + const pendingCompositionEnterRef = useRef(false) + + useLayoutEffect(() => { + const textarea = textareaRef.current + if (!textarea || compositionActiveRef.current || textarea.value === draft) { + return + } + textarea.value = draft + }, [draft, textareaRef]) + return (