Skip to content

Commit e799b6a

Browse files
fix(mobile): question answer field keeps up with Gboard autocorrect
The custom answer input took its value straight from the global draft atom. That atom re-renders through useSyncExternalStore on the sync lane, while TextInput's own text change state lands on the default lane, so the new value reached the input out of step with its event count and overwrote in-flight IME edits. The input now owns its text locally and adopts only draft changes it did not write, such as an option selection clearing it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 701e13c commit e799b6a

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎apps/mobile/src/features/threads/QuestionAttachments.tsx‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ export function QuestionAttachments(props: {
6464
});
6565
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- releases keyboard ownership on unmount, since an unmounted native input never emits blur
6666
useEffect(() => () => releaseFocus(), []);
67+
// The draft atom re-renders on the sync lane, ahead of TextInput's own event-count state, and
68+
// feeding that value straight in overwrites in-flight IME edits. Own the text locally and adopt
69+
// only drafts this input did not write, such as an option selection clearing it.
70+
const [text, setText] = useState(props.value);
71+
const writtenText = useRef(props.value);
72+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- adopts draft changes made outside this input; the ref tells them apart from our own writes, which reach props on another lane
73+
useEffect(() => {
74+
if (props.value === writtenText.current) return;
75+
writtenText.current = props.value;
76+
setText(props.value);
77+
}, [props.value]);
6778
const append = (
6879
key: string,
6980
attachments: Parameters<typeof appendComposerDraftAttachments>[1],
@@ -195,11 +206,15 @@ export function QuestionAttachments(props: {
195206
<VideoPreviewModal source={previewVideo} onRequestClose={() => setPreviewVideo(null)} />
196207
<TextInputWrapper onPaste={paste}>
197208
<TextInput
198-
value={props.value}
209+
value={text}
199210
multiline={props.question.initialAnswer !== undefined}
200211
submitBehavior={props.question.initialAnswer !== undefined ? "newline" : undefined}
201212
editable={!props.disabled}
202-
onChangeText={props.onChangeText}
213+
onChangeText={(next) => {
214+
writtenText.current = next;
215+
setText(next);
216+
props.onChangeText(next);
217+
}}
203218
onFocus={() => {
204219
focusedRef.current = true;
205220
onInputFocusChange?.(true);

0 commit comments

Comments
 (0)