@devries-cameron20 / t3code Mirror · read-only / commits / 5ceabb3fe8
Fork 0

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): a cold launch shows the cached thread rows with the first frame (#35683)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Theo Browne committed Nov 12, 2026 at 18:37 UTC 5ceabb3fe8f71a4fe10d50caa2411444a2f27d41
6 files changed +200 -15
apps/mobile/src/App.tsx
+30 -12
@@ -4,7 +4,7 @@ import { installThreadOutboxDelivery } from "./state/threadOutboxDelivery";
4 import * as Linking from "expo-linking";
5 import * as SplashScreen from "expo-splash-screen";
6 import { requireNativeModule } from "expo";
7 -import { useEffect, useState } from "react";
7 +import { useEffect, useRef, useState } from "react";
8 import { Platform, StatusBar } from "react-native";
9 import { GestureHandlerRootView } from "react-native-gesture-handler";
10 import { KeyboardProvider } from "react-native-keyboard-controller";
@@ -77,6 +77,12 @@ import { installUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarning
77 import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
78 import { installSubscriptionUsageRefresh } from "./widgets/useSubscriptionUsage";
79 import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl";
80 +import {
81 + launchSplashHomeRowsPending,
82 + settleLaunchSplashHomeRows,
83 + splashCanHide,
84 + useLaunchSplashHomeRowsPending,
85 +} from "./features/home/home-launch-splash";
86 import { restoreSettingsLinkState } from "./features/settings/settings-navigation";
87 import {
88 hydrateWorkspaceSelections,
@@ -166,6 +172,8 @@ function handleNavigationStateChange(state: NavigationState | undefined): void {
172 resolvePendingNewTaskPromptLink(state);
173 resolvePendingThreadPromptLink(state);
174 if (!state) return;
175 + // A launch that opens another route has no Home rows for the splash to wait for.
176 + if (state.routes[state.index]?.name !== "Home") settleLaunchSplashHomeRows();
177 setAgentNotificationPathname(workspaceLocationFromState(state).pathname);
178 recordAppShortcutNavigationState(state);
179 pruneNewTaskFlowStates(state);
@@ -204,28 +212,38 @@ disposeOnFoundationReplace(typeof module === "undefined" ? undefined : module.ho
212 for (const dispose of appServiceDisposers) dispose();
213 });
214
207 -// Cached shells are local reads that end in a fraction of this time; the limit only keeps a
208 -// failed read from holding the splash screen.
209 -const SPLASH_SHELL_CACHE_WAIT_MS = 1_500;
215 +// Cached shells are local reads that end in a fraction of this time; the limit keeps a failed
216 +// read, or a list that does not lay out, from holding the splash screen.
217 +const SPLASH_WAIT_MS = 1_500;
218
219 function SplashScreenCoordinator() {
220 const { isReady } = useAppearancePreferences();
221 const shellCachesRead = useAtomValue(shellCachesReadAtom);
222 + const homeRowsPending = useLaunchSplashHomeRowsPending();
223 const [waitEnded, setWaitEnded] = useState(false);
224 + const hidden = useRef(false);
225
216 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- starts the limit on how long the native splash screen waits for cached shells
226 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- starts the limit on how long the native splash screen waits for cached shells and their rows
227 useEffect(() => {
218 - const timer = setTimeout(() => setWaitEnded(true), SPLASH_SHELL_CACHE_WAIT_MS);
228 + const timer = setTimeout(() => setWaitEnded(true), SPLASH_WAIT_MS);
229 return () => clearTimeout(timer);
230 }, []);
231
222 - // The thread list paints every environment's cached rows at once when the splash hides
223 - // after they are read.
224 - const canHide = isReady && (shellCachesRead || waitEnded);
225 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- hides the native splash screen once preferences and cached shells have loaded
232 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- hides the native splash screen once preferences have loaded and the cached rows are laid out
233 useEffect(() => {
227 - if (canHide) void SplashScreen.hide();
228 - }, [canHide]);
234 + const canHide = splashCanHide({
235 + preferencesReady: isReady,
236 + shellCachesRead,
237 + // Home holds the splash in a layout effect of the commit that gives it rows. That can be
238 + // this commit, after this render read the store.
239 + homeRowsPending: homeRowsPending || launchSplashHomeRowsPending(),
240 + waitEnded,
241 + });
242 + if (!canHide || hidden.current) return;
243 + hidden.current = true;
244 + settleLaunchSplashHomeRows();
245 + void SplashScreen.hide();
246 + }, [isReady, shellCachesRead, homeRowsPending, waitEnded]);
247
248 return null;
249 }
apps/mobile/src/features/home/HomeRouteScreen.tsx
+1
@@ -239,6 +239,7 @@ export function HomeRouteScreen() {
239 selectedEnvironmentId={selectedEnvironmentId}
240 selectedProjectKey={selectedProjectKey}
241 threads={threads}
242 + visible={visible}
243 />
244 <ThreadUndoNotice visible={visible} />
245 </>
apps/mobile/src/features/home/HomeScreen.tsx
+22 -2
@@ -16,7 +16,15 @@ import { pickableProjectGroups } from "@t3tools/client-runtime/state/project-gro
16 import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
17 import { type EnvironmentId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
18 import { useAtomValue } from "@effect/atom-react";
19 -import { use, useEffect, useMemo, useRef, useState, type ComponentProps } from "react";
19 +import {
20 + use,
21 + useEffect,
22 + useLayoutEffect,
23 + useMemo,
24 + useRef,
25 + useState,
26 + type ComponentProps,
27 +} from "react";
28 import {
29 Platform,
30 ScrollView,
@@ -88,11 +96,14 @@ import {
96 import { createSwipeRowActivation } from "./swipe-row-activation";
97 import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "./thread-swipe-actions";
98 import { useFabScroll } from "./FabScrollContext";
99 +import { holdLaunchSplashForHomeRows, settleLaunchSplashHomeRows } from "./home-launch-splash";
100 import { useWorkspaceTabs } from "../layout/workspace/WorkspaceTabsContext";
101 import { ThreadListFilters } from "./ThreadListFilters";
102 import { deriveHomeEmptyState } from "./home-empty-state";
103
104 interface HomeScreenProps {
105 + /** Whether this list is the one on screen; see `useHomeRouteVisible`. */
106 + readonly visible: boolean;
107 readonly projects: ReadonlyArray<EnvironmentProject>;
108 readonly threads: ReadonlyArray<EnvironmentThreadShell>;
109 readonly pendingTasks: ReadonlyArray<PendingNewTask>;
@@ -597,6 +608,12 @@ export function HomeScreen(props: HomeScreenProps) {
608 props.threads.some((thread) => thread.archivedAt === null) ||
609 props.pendingTasks.length > 0 ||
610 threadListV2Layout.settledCount > 0;
611 + // A hidden list gets no layout, so it never reports its rows as laid out.
612 + const hasRowsToLayOut = props.visible && hasAnyThreads && threadListV2Items.length > 0;
613 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- holds the native launch splash, which is outside React, until the rows are gone or this list unmounts; a layout effect runs before the splash hides in this commit
614 + useLayoutEffect(() => {
615 + return hasRowsToLayOut ? holdLaunchSplashForHomeRows() : undefined;
616 + }, [hasRowsToLayOut]);
617 const selectedEnvironmentLabel =
618 props.selectedEnvironmentId === null
619 ? null
@@ -729,7 +746,10 @@ export function HomeScreen(props: HomeScreenProps) {
746 <AnimatedLegendList
747 itemLayoutAnimation={sidebarSurface ? THREAD_SIDEBAR_ROW_LAYOUT : undefined}
748 ref={listRef}
732 - onLoad={() => activateVisibleRows(threadListV2Items)}
749 + onLoad={() => {
750 + settleLaunchSplashHomeRows();
751 + activateVisibleRows(threadListV2Items);
752 + }}
753 onTouchStart={(event) => trackListTouches(event, true)}
754 onTouchEnd={(event) => trackListTouches(event, false)}
755 onTouchCancel={(event) => trackListTouches(event, false)}
apps/mobile/src/features/home/home-launch-splash.test.ts new
+70
@@ -0,0 +1,70 @@
1 +import { expect, it, vi } from "vite-plus/test";
2 +
3 +import { createLaunchSplashHomeRows, splashCanHide } from "./home-launch-splash";
4 +
5 +const launched = {
6 + preferencesReady: true,
7 + shellCachesRead: true,
8 + homeRowsPending: false,
9 + waitEnded: false,
10 +};
11 +
12 +it.each([
13 + {
14 + name: "hides when the cached shells are read and no rows wait for layout",
15 + input: launched,
16 + hides: true,
17 + },
18 + {
19 + name: "waits while Home still lays out the cached rows",
20 + input: { ...launched, homeRowsPending: true },
21 + hides: false,
22 + },
23 + {
24 + name: "waits for the cached shells when Home has no rows yet",
25 + input: { ...launched, shellCachesRead: false },
26 + hides: false,
27 + },
28 + {
29 + name: "stops waiting for rows at the limit",
30 + input: { ...launched, homeRowsPending: true, waitEnded: true },
31 + hides: true,
32 + },
33 + {
34 + name: "stops waiting for a cache read that fails at the limit",
35 + input: { ...launched, shellCachesRead: false, homeRowsPending: true, waitEnded: true },
36 + hides: true,
37 + },
38 + {
39 + name: "waits for preferences even after the limit",
40 + input: { ...launched, preferencesReady: false, waitEnded: true },
41 + hides: false,
42 + },
43 +])("the launch splash $name", ({ input, hides }) => {
44 + expect(splashCanHide(input)).toBe(hides);
45 +});
46 +
47 +it("the launch splash is held only while a Home list has rows to lay out", () => {
48 + const rows = createLaunchSplashHomeRows();
49 + const onChange = vi.fn();
50 + rows.subscribe(onChange);
51 +
52 + const release = rows.hold();
53 + expect(rows.pending()).toBe(true);
54 + // The server answered with no rows, or the list unmounted, before its first layout.
55 + release();
56 + expect(rows.pending(), "a list that lost its rows releases the splash").toBe(false);
57 + expect(onChange).toHaveBeenCalledTimes(2);
58 +
59 + const releaseLater = rows.hold();
60 + const releaseOther = rows.hold();
61 + releaseLater();
62 + release();
63 + expect(rows.pending(), "another list still has rows to lay out").toBe(true);
64 +
65 + rows.settle();
66 + expect(rows.pending()).toBe(false);
67 + releaseOther();
68 + rows.hold();
69 + expect(rows.pending(), "a list that mounts after the launch holds nothing").toBe(false);
70 +});
apps/mobile/src/features/home/home-launch-splash.ts new
+75
@@ -0,0 +1,75 @@
1 +import { useSyncExternalStore } from "react";
2 +
3 +/**
4 + * Whether the launch splash still waits for Home's list. A list holds the splash while it
5 + * has cached rows to lay out, so the first frame after the splash shows them.
6 + */
7 +export function createLaunchSplashHomeRows() {
8 + let holds = 0;
9 + let settled = false;
10 + const listeners = new Set<() => void>();
11 + const pending = () => !settled && holds > 0;
12 + const change = (apply: () => void) => {
13 + const before = pending();
14 + apply();
15 + if (pending() !== before) for (const listener of listeners) listener();
16 + };
17 + return {
18 + pending,
19 + /**
20 + * A Home list has rows that are not laid out yet. Call the returned release when it no
21 + * longer has them or unmounts; rows that come later can hold again.
22 + */
23 + hold: () => {
24 + let held = true;
25 + change(() => {
26 + holds += 1;
27 + });
28 + return () => {
29 + if (!held) return;
30 + held = false;
31 + change(() => {
32 + holds -= 1;
33 + });
34 + };
35 + },
36 + /**
37 + * The rows are laid out, the launch opened another route, or the splash is gone. It is
38 + * final: lists that mount after the launch must not hold anything.
39 + */
40 + settle: () =>
41 + change(() => {
42 + settled = true;
43 + }),
44 + subscribe: (onChange: () => void) => {
45 + listeners.add(onChange);
46 + return () => {
47 + listeners.delete(onChange);
48 + };
49 + },
50 + };
51 +}
52 +
53 +const homeRows = createLaunchSplashHomeRows();
54 +
55 +export const holdLaunchSplashForHomeRows = homeRows.hold;
56 +export const settleLaunchSplashHomeRows = homeRows.settle;
57 +export const launchSplashHomeRowsPending = homeRows.pending;
58 +
59 +export function useLaunchSplashHomeRowsPending(): boolean {
60 + return useSyncExternalStore(homeRows.subscribe, homeRows.pending);
61 +}
62 +
63 +/**
64 + * Whether the native splash can hide: after the cached shells are read and Home's list has
65 + * laid out their rows. One limit ends both waits.
66 + */
67 +export function splashCanHide(input: {
68 + readonly preferencesReady: boolean;
69 + readonly shellCachesRead: boolean;
70 + readonly homeRowsPending: boolean;
71 + readonly waitEnded: boolean;
72 +}): boolean {
73 + if (!input.preferencesReady) return false;
74 + return input.waitEnded || (input.shellCachesRead && !input.homeRowsPending);
75 +}
docs/internals/connection-runtime.md
+2 -1
@@ -103,7 +103,8 @@ thread's own shell, route checks) keep the live snapshot, where a row the server
103 sent must not look missing. The decision reads the snapshot's own sequence: a second
104 atom derived from the same shell state can be one update behind the rows. The mobile
105 splash screen also waits, for a bounded time, until every enabled environment has
106 -read its cached shell, so the first frame holds all cached rows.
106 +read its cached shell and Home's list has laid out those rows, so the first frame
107 +holds all cached rows.
108
109 Shell snapshots can leave rows out when the client asks. Servers that advertise
110 `shellThreadFamilies` leave out idle subagent children: a child stays while it