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): Back from a PR opened in a chat returns to the chat on Android (#27653)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
vivek committed
Nov 13, 2026 at 05:18 UTC
532bf2ee19aab2d419b920a7ffa69bb6e42035c3
15 files changed
+81
-91
apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+2
-5
@@ -112,7 +112,7 @@ import {
112
workspaceTabColumns,
113
workspaceTabNavigationState,
114
} from "./workspace/workspace-tab-navigation";
115
-import type { WorkspaceTab } from "./workspace/workspace-tabs-state";
115
+import { workspaceTabOf, type WorkspaceTab } from "./workspace/workspace-tabs-state";
116
import { workspaceRoutesOf } from "./workspace-overlay-routes";
117
import { SettingsWorkspaceLayout } from "../settings/SettingsWorkspaceLayout";
118
import { WorkspaceThreadSidebar } from "./workspace/WorkspaceThreadSidebar";
@@ -570,10 +570,7 @@ function AdaptiveWorkspaceLayoutContent(
570
setFileInspectorPreferredVisible(false);
571
setInspectorSheetRoute(null);
572
if (layout.variant === "medium") setPrimarySidebarVisible(false);
573
- workspace?.dispatch({
574
- type: "select",
575
- tab: detail.name === "Thread" ? "threads" : "pullRequests",
576
- });
573
+ workspace?.dispatch({ type: "select", tab: workspaceTabOf(detail.name) });
574
startOpeningDetail(detail);
575
navigation.dispatch(selectWorkspaceDetail(detail, sheet));
576
});
apps/mobile/src/features/layout/workspace/AndroidWorkspaceTabsProvider.tsx
+5
-1
@@ -3,6 +3,7 @@ import { createContext, use, type ReactNode } from "react";
3
import { Platform } from "react-native";
4
import { androidWorkspaceSettingsOpen } from "./android-workspace-tabs";
5
import { WorkspaceTabsProvider } from "./WorkspaceTabsContext";
6
+import { workspaceTabOf } from "./workspace-tabs-state";
7
8
interface AndroidWorkspaceRoot {
9
/**
@@ -35,7 +36,10 @@ export function AndroidWorkspaceTabsProvider(props: {
36
settingsIndex < 0 ? null : (props.state.routes[settingsIndex + 1]?.name ?? null);
37
const root = { key, settingsOpen, settingsRoute, settingsPage };
38
return Platform.OS === "android" ? (
38
- <WorkspaceTabsProvider>
39
+ // A cold-start link lands on a page with no list selection; start on that page's list.
40
+ <WorkspaceTabsProvider
41
+ initialTab={workspaceTabOf(props.state.routes.find((route) => route.name !== "Home")?.name)}
42
+ >
43
<AndroidWorkspaceRootContext value={root}>{props.children}</AndroidWorkspaceRootContext>
44
</WorkspaceTabsProvider>
45
) : (
apps/mobile/src/features/layout/workspace/WorkspaceTabsContext.tsx
+4
-3
@@ -54,8 +54,8 @@ function resolveWorkspaceTabsSelection(
54
55
// One model per provider. Handlers on frozen screens keep stale closures, so
56
// they read the current selection from the registry at call time.
57
-function createWorkspaceTabsModel() {
58
- const stored = Atom.make(initialWorkspaceTabsState());
57
+function createWorkspaceTabsModel(selectedTab?: WorkspaceTab) {
58
+ const stored = Atom.make(initialWorkspaceTabsState(selectedTab));
59
const scrollOffsets: Record<WorkspaceSearchTab, number> = {
60
threads: 0,
61
pullRequests: 0,
@@ -77,9 +77,10 @@ function createWorkspaceTabsModel() {
77
export function WorkspaceTabsProvider(props: {
78
readonly children: ReactNode;
79
readonly settingsOpen?: boolean;
80
+ readonly initialTab?: WorkspaceTab;
81
}) {
82
const registry = use(RegistryContext);
82
- const [model] = useState(createWorkspaceTabsModel);
83
+ const [model] = useState(() => createWorkspaceTabsModel(props.initialTab));
84
const state = useAtomValue(model.resolved);
85
const dispatch = (action: WorkspaceTabsAction) =>
86
registry.set(model.stored, workspaceTabsReducer(registry.get(model.resolved), action));
apps/mobile/src/features/layout/workspace/useAndroidWorkspaceNavigation.ts
+7
-28
@@ -1,50 +1,29 @@
1
import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
2
import { useCallback } from "react";
3
import { BackHandler, Keyboard, Platform } from "react-native";
4
-import {
5
- resetAndroidWorkspace,
6
- returnToAndroidWorkspaceList,
7
-} from "../../../lib/android-workspace-navigation";
8
-import { useWorkspaceTabs } from "./WorkspaceTabsContext";
9
-import type { WorkspaceTab } from "./workspace-tabs-state";
4
+import { returnToAndroidWorkspaceList } from "../../../lib/android-workspace-navigation";
5
11
-function useWorkspaceListNavigation(tab: WorkspaceTab) {
6
+export function useWorkspaceBackNavigation() {
7
const navigation = useNavigation();
13
- const dispatch = useWorkspaceTabs()?.dispatch;
8
return () => {
15
- if (Platform.OS === "android") {
16
- dispatch?.({ type: "select", tab });
17
- resetAndroidWorkspace(navigation);
18
- } else if (navigation.canGoBack()) navigation.goBack();
9
+ if (Platform.OS === "android") returnToAndroidWorkspaceList(navigation);
10
+ else if (navigation.canGoBack()) navigation.goBack();
11
else navigation.dispatch(StackActions.replace("Home"));
12
};
13
}
14
23
-export function useWorkspaceBackNavigation(tab: WorkspaceTab) {
24
- const navigation = useNavigation();
25
- const dispatch = useWorkspaceTabs()?.dispatch;
26
- const returnToList = useWorkspaceListNavigation(tab);
27
- return () => {
28
- if (Platform.OS === "android") {
29
- returnToAndroidWorkspaceList(navigation, () => dispatch?.({ type: "select", tab }));
30
- } else returnToList();
31
- };
32
-}
33
-
34
-export function useAndroidWorkspaceBack(tab: WorkspaceTab) {
35
- const dispatch = useWorkspaceTabs()?.dispatch;
36
- const goBack = useWorkspaceBackNavigation(tab);
15
+export function useAndroidWorkspaceBack() {
16
+ const goBack = useWorkspaceBackNavigation();
17
useFocusEffect(
18
useCallback(() => {
19
if (Platform.OS !== "android") return;
40
- dispatch?.({ type: "select", tab });
20
const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
21
if (Keyboard.isVisible()) Keyboard.dismiss();
22
else goBack();
23
return true;
24
});
25
return () => subscription.remove();
47
- }, [goBack, dispatch, tab]),
26
+ }, [goBack]),
27
);
28
return goBack;
29
}
apps/mobile/src/features/layout/workspace/workspace-tabs-state.ts
+9
-2
@@ -38,9 +38,16 @@ function emptyTab(): WorkspaceTabState {
38
return { query: "", searchMode: "resting", scrollOffset: 0, searchEntryOffset: 0 };
39
}
40
41
-export function initialWorkspaceTabsState(): WorkspaceTabsState {
41
+/** The list a workspace page belongs to. */
42
+export function workspaceTabOf(routeName: string | undefined): WorkspaceTab {
43
+ return routeName === "PullRequest" ? "pullRequests" : "threads";
44
+}
45
+
46
+export function initialWorkspaceTabsState(
47
+ selectedTab: WorkspaceTab = "threads",
48
+): WorkspaceTabsState {
49
return {
43
- selectedTab: "threads",
50
+ selectedTab,
51
selectionRevision: 0,
52
tabs: {
53
threads: emptyTab(),
apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+1
-1
@@ -358,7 +358,7 @@ function usePullRequestToolbarHeight(bottomInset: number) {
358
}
359
360
export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestParams>) {
361
- const returnToList = useAndroidWorkspaceBack("pullRequests");
361
+ const returnToList = useAndroidWorkspaceBack();
362
const { layout } = useAdaptiveWorkspaceLayout();
363
const navigation = useNavigation();
364
const insets = useSafeAreaInsets();
apps/mobile/src/features/pull-requests/PullRequestStackCard.tsx
+9
-7
@@ -1,6 +1,6 @@
1
+import { StackActions, useNavigation } from "@react-navigation/native";
2
import { useState } from "react";
3
import { View } from "react-native";
3
-import { useOpenWorkspaceDetail } from "../layout/useOpenWorkspaceDetail";
4
import { AppText as Text } from "../../components/ui/AppText";
5
import { PullRequestCardGroup, PullRequestCardRow } from "./PullRequestControls";
6
import { pullRequestLayerParams } from "./pullRequestStack";
@@ -14,7 +14,7 @@ export function PullRequestStackCard(props: {
14
readonly params: PullRequestParams;
15
readonly state: PullRequestStackState;
16
}) {
17
- const openDetail = useOpenWorkspaceDetail();
17
+ const navigation = useNavigation();
18
const [expanded, setExpanded] = useState(false);
19
const stack = props.state.stack;
20
if (!stack) {
@@ -66,12 +66,14 @@ export function PullRequestStackCard(props: {
66
selected
67
? undefined
68
: () =>
69
- openDetail({
70
- name: "PullRequest",
71
- params: withKnownPullRequestSummary(
72
- pullRequestLayerParams(props.params, layer.number),
69
+ navigation.dispatch(
70
+ StackActions.push(
71
+ "PullRequest",
72
+ withKnownPullRequestSummary(
73
+ pullRequestLayerParams(props.params, layer.number),
74
+ ),
75
),
74
- })
76
+ )
77
}
78
last={index === stack.layers.length - 1}
79
/>
apps/mobile/src/features/pull-requests/usePullRequestThreads.ts
+10
-5
@@ -3,7 +3,12 @@ import { visibleLinkedThreads } from "@t3tools/client-runtime/state/threads";
3
import { AsyncResult } from "effect/reactivity";
4
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
5
import * as Dialog from "../../components/ui/Dialog";
6
-import { useNavigationState, useRoute } from "@react-navigation/native";
6
+import {
7
+ StackActions,
8
+ useNavigation,
9
+ useNavigationState,
10
+ useRoute,
11
+} from "@react-navigation/native";
12
import { threadPullRequestLinkMode } from "@t3tools/client-runtime/thread-pull-request-compatibility";
13
import {
14
AuthOrchestrationOperateScope,
@@ -16,7 +21,6 @@ import { formatComposerContextReference } from "@t3tools/shared/composerContextR
21
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
22
import { normalizeThreadPullRequestKey } from "@t3tools/client-runtime/thread-pull-requests";
23
import { useRef, useState } from "react";
19
-import { useOpenWorkspaceDetail } from "../layout/useOpenWorkspaceDetail";
24
import { pullRequestComposerContext } from "../../lib/composerContext";
25
import { scopedThreadKey } from "../../lib/scopedEntities";
26
import { uuidv4 } from "../../lib/uuid";
@@ -82,14 +86,15 @@ export function usePullRequestThreads(
86
const canOperate = useEnvironmentScope(target.environmentId, AuthOrchestrationOperateScope);
87
const canAsk = !connected || canOperate;
88
const canCheckout = useEnvironmentScope(target.environmentId, AuthSourceControlWriteScope);
85
- const openDetail = useOpenWorkspaceDetail();
89
+ const navigation = useNavigation();
90
const pending = useRef(false);
91
const previousPrompts = useRef(new Map<string, string>());
92
const openThread = (thread: LinkedThread) => {
93
openThreadRoute({ environmentId: params.environmentId, threadId: thread.id });
94
};
91
- const openThreadRoute = (destination: ReactNavigation.RootParamList["Thread"]) =>
92
- openDetail({ name: "Thread", params: destination });
95
+ const openThreadRoute = (destination: ReactNavigation.RootParamList["Thread"]) => {
96
+ navigation.dispatch(StackActions.push("Thread", destination));
97
+ };
98
const [busy, setBusy] = useState(false);
99
const ask = async (thread?: LinkedThread, task: PullRequestAgentTask = "ask") => {
100
if (!pr || !canAsk || pending.current) return;
apps/mobile/src/features/threads/NewTaskDraftRouteScreen.tsx
+1
-1
@@ -90,7 +90,7 @@ const idleBranchCheckoutAtom = Atom.make(AsyncResult.initial<BranchCheckoutResul
90
91
export function NewTaskDraftRouteScreen({ route }: StaticScreenProps<NewTaskDraftRouteParams>) {
92
const currentRoute = useRoute();
93
- const goBack = useWorkspaceBackNavigation("threads");
93
+ const goBack = useWorkspaceBackNavigation();
94
const params = route.params ?? {};
95
const draftId = Array.isArray(params.draftId) ? params.draftId[0] : params.draftId;
96
const projects = useProjects();
apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
+1
-1
@@ -163,7 +163,7 @@ export function NewTaskDraftScreen(props: {
163
const flow = useNewTaskFlow();
164
const navigation = useNavigation();
165
const isFocused = useIsFocused();
166
- const goBack = useWorkspaceBackNavigation("threads");
166
+ const goBack = useWorkspaceBackNavigation();
167
const currentRoute = useRoute();
168
const flowKey = newTaskFlowKey(currentRoute);
169
const { getShare, isLoading: isIncomingShareInboxLoading } = useIncomingShare();
apps/mobile/src/features/threads/ThreadHeader.tsx
+1
-1
@@ -22,7 +22,7 @@ export function ThreadHeader(props: {
22
readonly inspectorMode: ThreadInspectorMode | null;
23
readonly onOpenFilesInspector: () => void;
24
}) {
25
- const goBack = useWorkspaceBackNavigation("threads");
25
+ const goBack = useWorkspaceBackNavigation();
26
const { toggleAuxiliaryPane, startNewTask } = useAdaptiveWorkspaceLayout();
27
const { panes } = useWorkspacePaneState();
28
const gitMenu = useThreadGitMenuDefinition(props.gitControls);
apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+2
-2
@@ -136,7 +136,7 @@ function firstRouteParam(value: string | string[] | undefined): string | null {
136
const InspectorHeaderShownContext = createContext(false);
137
138
function ThreadRouteFallbackLayout(props: { readonly children: ReactNode }) {
139
- const goBack = useWorkspaceBackNavigation("threads");
139
+ const goBack = useWorkspaceBackNavigation();
140
const inspectorHeaderShown = use(InspectorHeaderShownContext);
141
return (
142
<ThreadScreenFallback
@@ -241,7 +241,7 @@ export function ThreadRouteScreen(props: ThreadRouteScreenProps) {
241
}
242
243
function LiveThreadRouteController(props: ThreadRouteScreenProps) {
244
- useAndroidWorkspaceBack("threads");
244
+ useAndroidWorkspaceBack();
245
const connectionsReady = useConnectionsReady();
246
const { connectionState } = useRemoteConnectionStatus();
247
const { selectedThread } = useThreadSelection();
apps/mobile/src/lib/android-workspace-navigation.test.ts
+16
-15
@@ -85,13 +85,12 @@ function names(state: ReturnType<typeof router.getInitialState>) {
85
}
86
87
describe("Android workspace navigation", () => {
88
- it("returns to a distinct previous thread, otherwise to the workspace list", () => {
88
+ it("returns to the previous page, otherwise to the workspace list", () => {
89
const parent = withThread();
90
let state = apply(
91
parent,
92
StackActions.push("Thread", { ...thread.params, threadId: "child-a" }),
93
);
94
- let listSelected = false;
94
const navigation = {
95
dispatch: (action: RootStackResetAction) => {
96
state = apply(state, action);
@@ -102,39 +101,41 @@ describe("Android workspace navigation", () => {
101
state = apply(state, StackActions.pop());
102
},
103
};
105
- const back = () =>
106
- returnToAndroidWorkspaceList(navigation, () => {
107
- listSelected = true;
108
- });
104
+ const back = () => returnToAndroidWorkspaceList(navigation);
105
106
back();
107
expect(state.routes).toEqual(parent.routes);
108
expect(state.index).toBe(parent.index);
113
- expect(listSelected).toBe(false);
109
110
back();
111
expect(state.routes).toEqual([parent.routes[0]]);
112
expect(state.index).toBe(0);
118
- expect(listSelected).toBe(true);
113
114
state = apply(
115
parent,
116
StackActions.push("Thread", { ...thread.params, environmentId: "environment-b" }),
117
);
124
- listSelected = false;
118
back();
119
expect(state.routes).toEqual(parent.routes);
120
expect(state.index).toBe(parent.index);
128
- expect(listSelected).toBe(false);
121
+
122
+ const pullRequestOverThread = legacyHistory();
123
+ state = pullRequestOverThread;
124
+ back();
125
+ expect(state.routes).toEqual(pullRequestOverThread.routes.slice(0, 2));
126
127
// Confirming a Git action from the inline inspector can duplicate the current thread.
128
state = apply(parent, StackActions.push("Thread", thread.params));
129
back();
133
- expect({ routes: names(state), index: state.index, listSelected }).toEqual({
134
- routes: ["Home"],
135
- index: 0,
136
- listSelected: true,
137
- });
130
+ expect({ routes: names(state), index: state.index }).toEqual({ routes: ["Home"], index: 0 });
131
+
132
+ const child = { ...thread.params, threadId: "child-a" };
133
+ state = apply(
134
+ apply(parent, StackActions.push("Thread", child)),
135
+ StackActions.push("Thread", child),
136
+ );
137
+ back();
138
+ expect(state.routes).toEqual(parent.routes);
139
});
140
141
it("opens a linked thread above the current one so Back returns to it", () => {
apps/mobile/src/lib/android-workspace-navigation.ts
+12
-13
@@ -2,15 +2,14 @@ import type { NavigationState } from "@react-navigation/native";
2
import { isSettingsRoute } from "../features/settings/settings-navigation";
3
import { resetRootStack, type RootStackNavigation } from "./root-stack-reset";
4
5
-function androidWorkspaceBackReturnsToThread(state: NavigationState) {
6
- const current = state.routes[state.index];
7
- const params = current?.params as ReactNavigation.RootParamList["Thread"] | undefined;
8
- return (
9
- current?.name === "Thread" &&
10
- state.routes[state.index - 1]?.name === "Thread" &&
11
- params !== undefined &&
12
- !parentThreadIsBelow(state, params)
13
- );
5
+// Back follows history; Git confirmations can stack copies of the current thread, so skip those too.
6
+function androidWorkspaceBackTarget(state: NavigationState) {
7
+ let index = state.index;
8
+ const params = state.routes[index]?.params as ReactNavigation.RootParamList["Thread"] | undefined;
9
+ if (state.routes[index]?.name === "Thread" && params) {
10
+ while (parentThreadIsBelow({ ...state, index }, params)) index -= 1;
11
+ }
12
+ return index - 1;
13
}
14
15
/** The root stack with only the workspace list. */
@@ -60,12 +59,12 @@ export function linkedThreadStep(
59
60
export function returnToAndroidWorkspaceList(
61
navigation: RootStackNavigation & { readonly goBack: () => void },
63
- selectTab: () => void,
62
) {
63
const state = navigation.getState();
66
- if (state && androidWorkspaceBackReturnsToThread(state)) return navigation.goBack();
67
- selectTab();
68
- resetAndroidWorkspace(navigation);
64
+ const index = state ? androidWorkspaceBackTarget(state) : -1;
65
+ if (!state || index < 0) return resetAndroidWorkspace(navigation);
66
+ if (index === state.index - 1) return navigation.goBack();
67
+ resetRootStack(navigation, () => ({ ...state, index, routes: state.routes.slice(0, index + 1) }));
68
}
69
70
// Split view: Thread, PullRequest, and a Settings page picked from the list swap the detail pane
apps/mobile/src/native/useOpenPullRequest.ts
+1
-6
@@ -1,7 +1,5 @@
1
import { useNavigation, useRoute, StackActions } from "@react-navigation/native";
2
import { nativePullRequestDestination } from "../lib/pullRequestNavigation";
3
-import { Platform } from "react-native";
4
-import { useSelectWorkspaceDetail } from "../features/layout/workspace/useSelectWorkspaceDetail";
3
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
4
import { useProjects, useThreadShell } from "../state/entities";
5
import { tryOpenExternalUrl } from "../lib/openExternalUrl";
@@ -17,7 +15,6 @@ type PullRequestContext = { readonly environmentId: string; readonly projectId:
15
// Avoid useRoute so layouts without route context can open any thread's pull requests.
16
export function useNavigateToPullRequest(options?: { readonly replace?: boolean }) {
17
const navigation = useNavigation();
20
- const selectDetail = useSelectWorkspaceDetail();
18
const projects = useProjects();
19
const replace = options?.replace;
20
return async (url: string, context: PullRequestContext | null) => {
@@ -31,9 +28,7 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
28
...destination,
29
...(destination.navigationUrl ? { navigationId: nextLinkNavigationId() } : {}),
30
});
34
- // Android shows one page at a time; iOS opens it over the current page, so Back returns.
35
- if (Platform.OS === "android") selectDetail({ name: "PullRequest", params });
36
- else if (replace) navigation.dispatch(StackActions.replace("PullRequest", params));
31
+ if (replace) navigation.dispatch(StackActions.replace("PullRequest", params));
32
else navigation.dispatch(StackActions.push("PullRequest", params));
33
return true;
34
};