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, 13:15 UTC
fix(mobile): a thread opened while reconnecting no longer turns into a new draft (#26565)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Oct 29, 2026 at 06:03 UTC
a42bdd4e516433a16650b9401ab3c066544ca5cd
3 files changed
+122
-4
apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+25
-3
@@ -95,7 +95,11 @@ import {
95
ThreadInspectorContentStack,
96
type ThreadInspectorMode,
97
} from "./thread-inspector-content-stack";
98
-import { threadRouteIsHydrating } from "./thread-route-hydration";
98
+import {
99
+ threadDetailErrorIsCurrent,
100
+ threadRouteIsHydrating,
101
+ threadRouteOpensDraft,
102
+} from "./thread-route-hydration";
103
import { ThreadHeader } from "./ThreadHeader";
104
import {
105
useAndroidWorkspaceBack,
@@ -265,6 +269,13 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
269
? null
270
: scopedThreadKey(selectedThread.environmentId, selectedThread.id);
271
const selectedThreadDetailState = useSelectedThreadDetailState();
272
+ const detailError = selectedThreadDetailState.error;
273
+ const [errorBeforeConnected, setErrorBeforeConnected] = useState(() =>
274
+ routeConnectionState === "connected" ? Option.none<string>() : detailError,
275
+ );
276
+ if (routeConnectionState !== "connected" && errorBeforeConnected !== detailError) {
277
+ setErrorBeforeConnected(detailError);
278
+ }
279
const withInspectorHeader = (content: ReactNode) => (
280
<>
281
{props.inspectorPresentation ? (
@@ -297,14 +308,25 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
308
shellStatus: routeEnvironmentShellState.status,
309
shellHasError: routeEnvironmentShellState.hasError,
310
detailStatus: selectedThreadDetailState.status,
300
- detailHasError: Option.isSome(selectedThreadDetailState.error),
311
+ detailHasError: threadDetailErrorIsCurrent({
312
+ connectionState: routeConnectionState,
313
+ error: detailError,
314
+ errorBeforeConnected,
315
+ }),
316
});
317
318
if (stillHydrating) {
319
return withInspectorHeader(<OpeningThreadLoadingScreen />);
320
}
321
307
- if (routeName === "Thread" && !props.inspectorPresentation) {
322
+ if (
323
+ routeName === "Thread" &&
324
+ !props.inspectorPresentation &&
325
+ threadRouteOpensDraft({
326
+ connectionState: routeConnectionState,
327
+ detailStatus: selectedThreadDetailState.status,
328
+ })
329
+ ) {
330
return <UnavailableThreadDraftRedirect environmentId={environmentId} />;
331
}
332
apps/mobile/src/features/threads/thread-route-hydration.test.ts
+65
-1
@@ -1,6 +1,11 @@
1
+import * as Option from "effect/Option";
2
import { describe, expect, it } from "vite-plus/test";
3
3
-import { threadRouteIsHydrating } from "./thread-route-hydration";
4
+import {
5
+ threadDetailErrorIsCurrent,
6
+ threadRouteIsHydrating,
7
+ threadRouteOpensDraft,
8
+} from "./thread-route-hydration";
9
10
const settled = {
11
isLoadingConnections: false,
@@ -89,3 +94,62 @@ describe("threadRouteIsHydrating", () => {
94
).toBe(false);
95
});
96
});
97
+
98
+describe("threadRouteOpensDraft", () => {
99
+ it("keeps the route while a reconnecting environment may still deliver the thread", () => {
100
+ expect(threadRouteOpensDraft({ connectionState: "reconnecting", detailStatus: "empty" })).toBe(
101
+ false,
102
+ );
103
+ });
104
+
105
+ it("keeps the route while Reconnect retries a thread that failed to sync", () => {
106
+ const failedDetail = {
107
+ ...settled,
108
+ connectionState: "connecting" as const,
109
+ detailStatus: "empty" as const,
110
+ detailHasError: true,
111
+ };
112
+ expect(threadRouteIsHydrating(failedDetail)).toBe(false);
113
+ expect(threadRouteOpensDraft(failedDetail)).toBe(false);
114
+ });
115
+
116
+ it("opens a draft once the thread can't arrive", () => {
117
+ expect(
118
+ threadRouteOpensDraft({ connectionState: "reconnecting", detailStatus: "deleted" }),
119
+ ).toBe(true);
120
+ expect(threadRouteOpensDraft({ connectionState: "offline", detailStatus: "empty" })).toBe(true);
121
+ });
122
+});
123
+
124
+describe("threadDetailErrorIsCurrent", () => {
125
+ const oldError = Option.some("Could not synchronize the thread.");
126
+
127
+ it("ignores the error a thread kept from before the connection came back", () => {
128
+ const detailHasError = threadDetailErrorIsCurrent({
129
+ connectionState: "connected",
130
+ error: oldError,
131
+ errorBeforeConnected: oldError,
132
+ });
133
+ expect(detailHasError).toBe(false);
134
+ expect(threadRouteIsHydrating({ ...settled, detailStatus: "empty", detailHasError })).toBe(
135
+ true,
136
+ );
137
+ });
138
+
139
+ it("counts an error the live connection reported", () => {
140
+ expect(
141
+ threadDetailErrorIsCurrent({
142
+ connectionState: "connected",
143
+ error: Option.some("Could not synchronize the thread."),
144
+ errorBeforeConnected: oldError,
145
+ }),
146
+ ).toBe(true);
147
+ expect(
148
+ threadDetailErrorIsCurrent({
149
+ connectionState: "reconnecting",
150
+ error: oldError,
151
+ errorBeforeConnected: oldError,
152
+ }),
153
+ ).toBe(true);
154
+ });
155
+});
apps/mobile/src/features/threads/thread-route-hydration.ts
+32
@@ -1,6 +1,7 @@
1
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2
import type { EnvironmentShellStatus } from "@t3tools/client-runtime/state/shell";
3
import type { EnvironmentThreadStatus } from "@t3tools/client-runtime/state/threads";
4
+import * as Option from "effect/Option";
5
6
export function threadRouteIsHydrating(input: {
7
readonly isLoadingConnections: boolean;
@@ -41,3 +42,34 @@ export function threadRouteIsHydrating(input: {
42
(input.connectionState === "connected" && input.detailStatus === "empty")
43
);
44
}
45
+
46
+/**
47
+ * Replacing the route with a draft can't be undone, so a thread that may still arrive keeps its
48
+ * route: a reconnecting environment often delivers it moments later, and Reconnect starts a
49
+ * fresh connecting attempt.
50
+ */
51
+export function threadRouteOpensDraft(input: {
52
+ readonly connectionState: EnvironmentConnectionPhase;
53
+ readonly detailStatus: EnvironmentThreadStatus;
54
+}): boolean {
55
+ if (input.detailStatus === "deleted") {
56
+ return true;
57
+ }
58
+ return input.connectionState !== "reconnecting" && input.connectionState !== "connecting";
59
+}
60
+
61
+/**
62
+ * A thread keeps its sync error until the new connection resubscribes, so the first renders after
63
+ * a reconnect still show the old connection's error. Only an error the live connection reported
64
+ * counts.
65
+ */
66
+export function threadDetailErrorIsCurrent<E>(input: {
67
+ readonly connectionState: EnvironmentConnectionPhase;
68
+ readonly error: Option.Option<E>;
69
+ readonly errorBeforeConnected: Option.Option<E>;
70
+}): boolean {
71
+ return (
72
+ Option.isSome(input.error) &&
73
+ !(input.connectionState === "connected" && input.error === input.errorBeforeConnected)
74
+ );
75
+}