The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 04:30 UTC
fix(mobile): composer keeps the keyboard when a queued edit ends (#31317)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Nov 5, 2026 at 14:19 UTC
337c5858c33bc7f8f6dfd391a2c279fa0f7e4d17
3 files changed
+25
-9
apps/mobile/src/components/ComposerEditor.ios.test.tsx
+7
-2
@@ -20,6 +20,7 @@ const native = vi.hoisted(() => ({
20
text: "",
21
eventCount: 0,
22
resetGeneration: 0,
23
+ mounts: 0,
24
props: null as NativeProps | null,
25
deliver: null as ((event: NativeEvent) => void) | null,
26
}));
@@ -28,6 +29,7 @@ function NativeView(props: NativeProps) {
29
const propsRef = useRef(props);
30
useLayoutEffect(() => {
31
Object.assign(native, { text: "", eventCount: 0, resetGeneration: 0 });
32
+ native.mounts += 1;
33
}, []);
34
useLayoutEffect(() => {
35
propsRef.current = props;
@@ -173,13 +175,16 @@ it("keeps a pending event from the previous native editor out of the selected dr
175
);
176
await act(async () => renderDraft(first));
177
const deliverPendingEvent = native.deliver!;
178
+ const pending = { eventCount: native.eventCount + 1, resetGeneration: native.resetGeneration };
179
+ const mounts = native.mounts;
180
await act(async () => renderDraft(second));
181
+ // Remounting the native view would drop the keyboard mid-edit.
182
+ expect(native.mounts).toBe(mounts);
183
await act(async () =>
184
deliverPendingEvent({
185
value: "Draft A corrected",
186
selection: { start: 17, end: 17 },
181
- eventCount: 1,
182
- resetGeneration: 0,
187
+ ...pending,
188
}),
189
);
190
expect(getComposerDraftSnapshot(second).text).toBe("Draft B");
apps/mobile/src/components/ComposerEditor.tsx
+1
-1
@@ -177,7 +177,7 @@ export function ComposerEditor({
177
<>
178
{/* Reset revision history with the recreated iOS view without aborting context imports. */}
179
<NativeComposerEditor
180
- key={`${hidden ? "hidden" : "visible"}:${draftKey ?? "no-draft"}`}
180
+ key={hidden ? "hidden" : "visible"}
181
{...props}
182
enterBehavior={props.enterBehavior ?? preferredEnterBehavior}
183
onChangeText={changeText}
apps/mobile/src/state/use-composer-drafts.ts
+17
-6
@@ -21,7 +21,7 @@ import {
21
type ScopedThreadRef,
22
} from "@t3tools/contracts";
23
import * as Schema from "effect/Schema";
24
-import { useEffect } from "react";
24
+import { useEffect, useState } from "react";
25
import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity";
26
import * as Option from "effect/Option";
27
import { parseScopedThreadKey, scopedThreadKey } from "@t3tools/client-runtime/environment";
@@ -112,20 +112,31 @@ const composerDraftResetAtom = Atom.family((_draftKey: string) =>
112
);
113
const NO_COMPOSER_DRAFT_RESET_ATOM = Atom.make(0);
114
115
-function markComposerDraftReset(draftKey: string): void {
115
+function nextComposerDraftReset(): number {
116
lastComposerDraftReset += 1;
117
- appAtomRegistry.set(composerDraftResetAtom(draftKey), lastComposerDraftReset);
117
+ return lastComposerDraftReset;
118
+}
119
+
120
+function markComposerDraftReset(draftKey: string): void {
121
+ appAtomRegistry.set(composerDraftResetAtom(draftKey), nextComposerDraftReset());
122
}
123
124
/**
121
- * Raised when a draft's text is replaced outright (sent, discarded). Native editor events read it
122
- * synchronously, so an edit the editor made before applying the reset cannot restore the text.
125
+ * Raised when a draft's text is replaced outright (sent, discarded), or when the editor switches
126
+ * drafts. iOS editor events read it synchronously, so an edit the editor made before applying the
127
+ * reset cannot restore the text or land in the next draft. Android ignores it.
128
*/
129
export function useComposerDraftResetGeneration(draftKey: string | null): () => number {
130
const atom = draftKey === null ? NO_COMPOSER_DRAFT_RESET_ATOM : composerDraftResetAtom(draftKey);
131
// Subscribing re-renders the editor so it sends the reset even when the text did not change.
132
useAtomValue(atom);
128
- return () => appAtomRegistry.get(atom);
133
+ // The editor stays mounted across drafts (remounting drops the keyboard), so a switch takes a
134
+ // fresh generation; the selected draft's own, possibly older, stamp would move it backwards.
135
+ const [selected, setSelected] = useState({ draftKey, generation: 0 });
136
+ if (selected.draftKey !== draftKey) {
137
+ setSelected({ draftKey, generation: nextComposerDraftReset() });
138
+ }
139
+ return () => Math.max(selected.generation, appAtomRegistry.get(atom));
140
}
141
142
export function rememberComposerDraftSelection(