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 21, 18:30 UTC
fix(mobile): show loading until existing threads are known (#28663)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
shivam committed
Nov 13, 2026 at 04:42 UTC
bc0befe90a02a7e67b031829fe90d029526fa278
6 files changed
+224
-83
apps/mobile/src/features/home/HomeScreen.tsx
+5
-78
@@ -90,6 +90,7 @@ import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "./thread-sw
90
import { useFabScroll } from "./FabScrollContext";
91
import { useWorkspaceTabs } from "../layout/workspace/WorkspaceTabsContext";
92
import { ThreadListFilters } from "./ThreadListFilters";
93
+import { deriveHomeEmptyState } from "./home-empty-state";
94
95
interface HomeScreenProps {
96
readonly projects: ReadonlyArray<EnvironmentProject>;
@@ -145,73 +146,6 @@ const ESTIMATED_THREAD_LIST_V2_ROW_HEIGHT = 72;
146
// rows that are already built instead of rows still being rebuilt.
147
const THREAD_LIST_V2_DRAW_DISTANCE = 1_000;
148
148
-function deriveEmptyState(props: {
149
- readonly catalogState: WorkspaceState;
150
- readonly projectCount: number;
151
-}): { readonly title: string; readonly detail: string; readonly loading: boolean } {
152
- const { catalogState } = props;
153
- if (catalogState.isLoadingConnections) {
154
- return {
155
- title: "Loading environments",
156
- detail: "Checking saved environments on this device.",
157
- loading: true,
158
- };
159
- }
160
-
161
- if (!catalogState.hasConnections) {
162
- return {
163
- title: "No environments connected",
164
- detail: "Add an environment to load projects and start coding sessions.",
165
- loading: false,
166
- };
167
- }
168
-
169
- if (
170
- (catalogState.connectionState === "available" ||
171
- catalogState.connectionState === "offline" ||
172
- catalogState.connectionState === "error" ||
173
- catalogState.connectionState === "unsupported") &&
174
- !catalogState.hasLoadedShellSnapshot
175
- ) {
176
- return {
177
- title:
178
- catalogState.connectionState === "unsupported"
179
- ? "Client not supported"
180
- : "Environment unavailable",
181
- detail:
182
- catalogState.connectionError ??
183
- "The saved environment is offline. Check the URL or start the environment, then retry.",
184
- loading: false,
185
- };
186
- }
187
-
188
- if (
189
- catalogState.hasConnectingEnvironment &&
190
- !catalogState.hasLoadedShellSnapshot &&
191
- catalogState.connectionError === null
192
- ) {
193
- return {
194
- title: "Connecting to environment",
195
- detail: "Loading projects and threads from the saved environment.",
196
- loading: true,
197
- };
198
- }
199
-
200
- if (props.projectCount === 0 && catalogState.hasLoadedShellSnapshot) {
201
- return {
202
- title: "No projects found",
203
- detail: "The connected environment did not report any projects.",
204
- loading: false,
205
- };
206
- }
207
-
208
- return {
209
- title: "No threads yet",
210
- detail: "Create a task to start a new coding runtime in one of your connected projects.",
211
- loading: false,
212
- };
213
-}
214
-
149
function HomeTopContentSpacer() {
150
return <View className="h-4" />;
151
}
@@ -668,10 +602,7 @@ export function HomeScreen(props: HomeScreenProps) {
602
? null
603
: (props.savedConnectionsById[props.selectedEnvironmentId]?.environmentLabel ??
604
"this environment");
671
- const emptyState = deriveEmptyState({
672
- catalogState: props.catalogState,
673
- projectCount: props.projects.length,
674
- });
605
+ const emptyState = deriveHomeEmptyState(props.catalogState, props.projects.length);
606
607
if (!hasAnyThreads) {
608
return (
@@ -694,14 +625,10 @@ export function HomeScreen(props: HomeScreenProps) {
625
<EmptyState
626
title={emptyState.title}
627
detail={emptyState.detail}
697
- actionLabel={
698
- !props.catalogState.hasReadyEnvironment ? "Add environment" : undefined
699
- }
700
- onAction={
701
- !props.catalogState.hasReadyEnvironment ? props.onAddConnection : undefined
702
- }
628
+ actionLabel={emptyState.showsAddEnvironment ? "Add environment" : undefined}
629
+ onAction={emptyState.showsAddEnvironment ? props.onAddConnection : undefined}
630
action={
704
- Platform.OS === "android" && !props.catalogState.hasReadyEnvironment ? (
631
+ Platform.OS === "android" && emptyState.showsAddEnvironment ? (
632
<FloatingActionButton
633
label="Add environment"
634
icon="plus"
apps/mobile/src/features/home/home-empty-state.test.ts
new
+104
@@ -0,0 +1,104 @@
1
+import { EnvironmentId } from "@t3tools/contracts";
2
+import { describe, expect, it } from "vite-plus/test";
3
+
4
+import type { WorkspaceEnvironment, WorkspaceState } from "../../state/workspaceModel";
5
+import { deriveHomeEmptyState } from "./home-empty-state";
6
+
7
+function connectingEnvironment(
8
+ connectionState: "connecting" | "reconnecting",
9
+ connectionError: string | null,
10
+): WorkspaceEnvironment {
11
+ return {
12
+ environmentId: EnvironmentId.make("environment-1"),
13
+ environmentLabel: "corex",
14
+ displayUrl: "",
15
+ isRelayManaged: false,
16
+ isEnabled: true,
17
+ connectionState,
18
+ connectionError,
19
+ connectionErrorTraceId: null,
20
+ };
21
+}
22
+
23
+function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState {
24
+ return {
25
+ isLoadingConnections: false,
26
+ hasConnections: true,
27
+ hasLoadedShellSnapshot: true,
28
+ hasPendingShellSnapshot: false,
29
+ hasSyncingConnectedEnvironment: false,
30
+ hasReadyEnvironment: true,
31
+ hasConnectingEnvironment: false,
32
+ connectingEnvironments: [],
33
+ connectionState: "connected",
34
+ connectionError: null,
35
+ shellSnapshotError: null,
36
+ networkStatus: "online",
37
+ ...overrides,
38
+ };
39
+}
40
+
41
+const RETAINED_FAILURE = "Environment did not respond before the connection timeout.";
42
+const reconnecting = connectingEnvironment("reconnecting", RETAINED_FAILURE);
43
+
44
+describe("home empty state", () => {
45
+ it.each([
46
+ [
47
+ "waits while a saved environment retries after a retained failure",
48
+ workspaceState({
49
+ hasLoadedShellSnapshot: false,
50
+ hasPendingShellSnapshot: true,
51
+ hasReadyEnvironment: false,
52
+ hasConnectingEnvironment: true,
53
+ connectingEnvironments: [reconnecting],
54
+ connectionState: "reconnecting",
55
+ connectionError: RETAINED_FAILURE,
56
+ }),
57
+ 1,
58
+ { title: "Connecting to environment", loading: true, showsAddEnvironment: false },
59
+ ],
60
+ [
61
+ "waits for a connected environment's first shell snapshot",
62
+ workspaceState({
63
+ hasLoadedShellSnapshot: false,
64
+ hasPendingShellSnapshot: true,
65
+ hasSyncingConnectedEnvironment: true,
66
+ }),
67
+ 0,
68
+ { title: "Loading threads", loading: true, showsAddEnvironment: false },
69
+ ],
70
+ [
71
+ "waits while another environment is still connecting after one loaded empty",
72
+ workspaceState({
73
+ hasPendingShellSnapshot: true,
74
+ hasConnectingEnvironment: true,
75
+ connectingEnvironments: [reconnecting],
76
+ connectionError: RETAINED_FAILURE,
77
+ }),
78
+ 0,
79
+ { title: "Loading threads", loading: true, showsAddEnvironment: false },
80
+ ],
81
+ [
82
+ "reports no threads once every environment has resolved",
83
+ workspaceState(),
84
+ 1,
85
+ { title: "No threads yet", loading: false, showsAddEnvironment: false },
86
+ ],
87
+ [
88
+ "does not wait on retries while the device is offline",
89
+ workspaceState({
90
+ hasPendingShellSnapshot: true,
91
+ hasReadyEnvironment: false,
92
+ hasConnectingEnvironment: true,
93
+ connectingEnvironments: [reconnecting],
94
+ connectionState: "offline",
95
+ networkStatus: "offline",
96
+ }),
97
+ 1,
98
+ { title: "No threads yet", loading: false, showsAddEnvironment: true },
99
+ ],
100
+ ] as const)("%s", (_name, state, projectCount, expected) => {
101
+ const { title, loading, showsAddEnvironment } = deriveHomeEmptyState(state, projectCount);
102
+ expect({ title, loading, showsAddEnvironment }).toEqual(expected);
103
+ });
104
+});
apps/mobile/src/features/home/home-empty-state.ts
new
+81
@@ -0,0 +1,81 @@
1
+import { isWorkspaceCatalogPending, type WorkspaceState } from "../../state/workspaceModel";
2
+
3
+export interface HomeEmptyState {
4
+ readonly title: string;
5
+ readonly detail: string;
6
+ readonly loading: boolean;
7
+ readonly showsAddEnvironment: boolean;
8
+}
9
+
10
+export function deriveHomeEmptyState(
11
+ catalogState: WorkspaceState,
12
+ projectCount: number,
13
+): HomeEmptyState {
14
+ const emptyState = deriveEmptyState(catalogState, projectCount);
15
+ return {
16
+ ...emptyState,
17
+ showsAddEnvironment: !emptyState.loading && !catalogState.hasReadyEnvironment,
18
+ };
19
+}
20
+
21
+function deriveEmptyState(
22
+ catalogState: WorkspaceState,
23
+ projectCount: number,
24
+): Omit<HomeEmptyState, "showsAddEnvironment"> {
25
+ if (catalogState.isLoadingConnections) {
26
+ return {
27
+ title: "Loading environments",
28
+ detail: "Checking saved environments on this device.",
29
+ loading: true,
30
+ };
31
+ }
32
+
33
+ if (!catalogState.hasConnections) {
34
+ return {
35
+ title: "No environments connected",
36
+ detail: "Add an environment to load projects and start coding sessions.",
37
+ loading: false,
38
+ };
39
+ }
40
+
41
+ if (
42
+ (catalogState.connectionState === "available" ||
43
+ catalogState.connectionState === "offline" ||
44
+ catalogState.connectionState === "error" ||
45
+ catalogState.connectionState === "unsupported") &&
46
+ !catalogState.hasLoadedShellSnapshot
47
+ ) {
48
+ return {
49
+ title:
50
+ catalogState.connectionState === "unsupported"
51
+ ? "Client not supported"
52
+ : "Environment unavailable",
53
+ detail:
54
+ catalogState.connectionError ??
55
+ "The saved environment is offline. Check the URL or start the environment, then retry.",
56
+ loading: false,
57
+ };
58
+ }
59
+
60
+ if (isWorkspaceCatalogPending(catalogState)) {
61
+ return {
62
+ title: catalogState.hasReadyEnvironment ? "Loading threads" : "Connecting to environment",
63
+ detail: "Loading projects and threads from the saved environment.",
64
+ loading: true,
65
+ };
66
+ }
67
+
68
+ if (projectCount === 0 && catalogState.hasLoadedShellSnapshot) {
69
+ return {
70
+ title: "No projects found",
71
+ detail: "The connected environment did not report any projects.",
72
+ loading: false,
73
+ };
74
+ }
75
+
76
+ return {
77
+ title: "No threads yet",
78
+ detail: "Create a task to start a new coding runtime in one of your connected projects.",
79
+ loading: false,
80
+ };
81
+}
apps/mobile/src/state/workspace.ts
+2
-2
@@ -2,7 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
2
import { Atom } from "effect/reactivity";
3
4
import { environmentShell, environmentShellSummaryAtom } from "./shell";
5
-import { projectWorkspaceState } from "./workspaceModel";
5
+import { isEnvironmentShellPending, projectWorkspaceState } from "./workspaceModel";
6
import { environmentCatalog } from "../connection/catalog";
7
import { environmentPresentations } from "./presentation";
8
import { createWorkspaceConnectionAtoms } from "./workspace-connection-atoms";
@@ -19,7 +19,7 @@ const hasSyncingConnectedEnvironmentAtom = Atom.make((get) =>
19
(environment) =>
20
environment.isEnabled &&
21
environment.connectionState === "connected" &&
22
- get(environmentShell.stateValueAtom(environment.environmentId)).status === "synchronizing",
22
+ isEnvironmentShellPending(get(environmentShell.stateValueAtom(environment.environmentId))),
23
),
24
).pipe(Atom.withLabel("mobile:has-syncing-connected-environment"));
25
apps/mobile/src/state/workspaceModel.test.ts
+14
-2
@@ -1,4 +1,7 @@
1
-import type { EnvironmentShellSummary } from "@t3tools/client-runtime/state/shell";
1
+import {
2
+ EMPTY_SHELL_STATE,
3
+ type EnvironmentShellSummary,
4
+} from "@t3tools/client-runtime/state/shell";
5
import {
6
BearerConnectionProfile,
7
BearerConnectionTarget,
@@ -7,7 +10,7 @@ import { EnvironmentId } from "@t3tools/contracts";
10
import { describe, expect, it } from "@effect/vitest";
11
import * as Option from "effect/Option";
12
10
-import { projectWorkspaceState } from "./workspaceModel";
13
+import { isEnvironmentShellPending, projectWorkspaceState } from "./workspaceModel";
14
import { projectEnvironmentConnectionSummary as projectWorkspaceEnvironment } from "@t3tools/client-runtime/state/presentation";
15
import type { EnvironmentPresentation } from "./environments";
16
@@ -76,6 +79,15 @@ describe("mobile workspace projection", () => {
79
expect(state.hasReadyEnvironment).toBe(false);
80
});
81
82
+ it("waits for shell cache initialization and synchronization, but not completed reads", () => {
83
+ expect(isEnvironmentShellPending(EMPTY_SHELL_STATE)).toBe(true);
84
+ expect(isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, status: "synchronizing" })).toBe(true);
85
+ expect(isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, status: "cached" })).toBe(false);
86
+ expect(
87
+ isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, error: Option.some("Cache failed.") }),
88
+ ).toBe(false);
89
+ });
90
+
91
it("keeps retained snapshots visible while reconnecting without claiming readiness", () => {
92
const environments = [projectWorkspaceEnvironment(ENVIRONMENT_ID, environment("reconnecting"))];
93
const state = projectWorkspaceState({
apps/mobile/src/state/workspaceModel.ts
+18
-1
@@ -1,4 +1,8 @@
1
-import { type EnvironmentShellSummary } from "@t3tools/client-runtime/state/shell";
1
+import {
2
+ EMPTY_SHELL_STATE,
3
+ type EnvironmentShellState,
4
+ type EnvironmentShellSummary,
5
+} from "@t3tools/client-runtime/state/shell";
6
import type { EnvironmentId, ServerConfig } from "@t3tools/contracts";
7
8
import {
@@ -103,4 +107,17 @@ export function projectWorkspaceState(input: {
107
};
108
}
109
110
+// The atom starts at EMPTY_SHELL_STATE itself; any state after the cache read is a new object.
111
+export function isEnvironmentShellPending(state: EnvironmentShellState): boolean {
112
+ return state === EMPTY_SHELL_STATE || state.status === "synchronizing";
113
+}
114
+
115
+// Reconnecting environments keep their last failure, so an error alone does not end the wait.
116
+export function isWorkspaceCatalogPending(state: WorkspaceState): boolean {
117
+ return (
118
+ state.networkStatus !== "offline" &&
119
+ (state.hasConnectingEnvironment || state.hasSyncingConnectedEnvironment)
120
+ );
121
+}
122
+
123
export type ServerConfigByEnvironmentId = ReadonlyMap<EnvironmentId, ServerConfig>;