Skip to content

Commit a5b70ac

Browse files
shivamhwpclaude
andcommitted
fix(mobile): a thread opened while reconnecting no longer turns into a new draft
Opening a thread the phone hasn't cached while its environment retries a failed connection replaced the route with a new-thread draft. The thread then synced seconds later, but the draft stayed. While the environment is reconnecting, the route now keeps the "Thread unavailable" card with its Reconnect action and shows the thread once it arrives. Offline, failed, removed and deleted cases still open a draft, as #25627 intended. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5211acf commit a5b70ac

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import {
9595
ThreadInspectorContentStack,
9696
type ThreadInspectorMode,
9797
} from "./thread-inspector-content-stack";
98-
import { threadRouteIsHydrating } from "./thread-route-hydration";
98+
import { threadRouteIsHydrating, threadRouteOpensDraft } from "./thread-route-hydration";
9999
import { ThreadHeader } from "./ThreadHeader";
100100
import {
101101
useAndroidWorkspaceBack,
@@ -304,7 +304,14 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
304304
return withInspectorHeader(<OpeningThreadLoadingScreen />);
305305
}
306306

307-
if (routeName === "Thread" && !props.inspectorPresentation) {
307+
if (
308+
routeName === "Thread" &&
309+
!props.inspectorPresentation &&
310+
threadRouteOpensDraft({
311+
connectionState: routeConnectionState,
312+
detailStatus: selectedThreadDetailState.status,
313+
})
314+
) {
308315
return <UnavailableThreadDraftRedirect environmentId={environmentId} />;
309316
}
310317

‎apps/mobile/src/features/threads/thread-route-hydration.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import { threadRouteIsHydrating } from "./thread-route-hydration";
3+
import { threadRouteIsHydrating, threadRouteOpensDraft } from "./thread-route-hydration";
44

55
const settled = {
66
isLoadingConnections: false,
@@ -89,3 +89,23 @@ describe("threadRouteIsHydrating", () => {
8989
).toBe(false);
9090
});
9191
});
92+
93+
describe("threadRouteOpensDraft", () => {
94+
it("keeps the route while a reconnecting environment may still deliver the thread", () => {
95+
expect(threadRouteOpensDraft({ connectionState: "reconnecting", detailStatus: "empty" })).toBe(
96+
false,
97+
);
98+
expect(
99+
threadRouteOpensDraft({ connectionState: "reconnecting", detailStatus: "synchronizing" }),
100+
).toBe(false);
101+
});
102+
103+
it("opens a draft once the thread can't arrive", () => {
104+
expect(
105+
threadRouteOpensDraft({ connectionState: "reconnecting", detailStatus: "deleted" }),
106+
).toBe(true);
107+
for (const connectionState of ["offline", "error", "available", "connected"] as const) {
108+
expect(threadRouteOpensDraft({ connectionState, detailStatus: "empty" })).toBe(true);
109+
}
110+
});
111+
});

‎apps/mobile/src/features/threads/thread-route-hydration.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@ export function threadRouteIsHydrating(input: {
4141
(input.connectionState === "connected" && input.detailStatus === "empty")
4242
);
4343
}
44+
45+
/**
46+
* Replacing the route with a draft can't be undone, so a thread that may still arrive keeps its
47+
* route: a reconnecting environment often delivers it moments later.
48+
*/
49+
export function threadRouteOpensDraft(input: {
50+
readonly connectionState: EnvironmentConnectionPhase;
51+
readonly detailStatus: EnvironmentThreadStatus;
52+
}): boolean {
53+
return input.connectionState !== "reconnecting" || input.detailStatus === "deleted";
54+
}

0 commit comments

Comments
 (0)