The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): keep chat open when branch actions finish after dismissal (#39562)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 20, 2026 at 08:52 UTC
16d40942ac9db0745bcabbfe18f85fb6dcda89ae
2 files changed
+53
-14
apps/mobile/src/features/threads/git/GitBranchesSheet.test.tsx
+50
-11
@@ -14,9 +14,17 @@ const state = vi.hoisted(() => ({
14
inputs: new Map<string, InputProps>(),
15
actions: new Map<string, ActionProps>(),
16
worktrees: [] as Array<{ baseBranch: string; newBranch: string }>,
17
+ focused: true,
18
+ goBackCalls: 0,
19
+ gitResult: Promise.resolve<object | null>(null),
20
}));
21
19
-vi.mock("@react-navigation/native", () => ({ useNavigation: () => ({ goBack() {} }) }));
22
+vi.mock("@react-navigation/native", () => ({
23
+ useNavigation: () => ({
24
+ goBack: () => state.goBackCalls++,
25
+ isFocused: () => state.focused,
26
+ }),
27
+}));
28
vi.mock("../../../components/ui/SheetHeader", () => ({ SheetHeader: () => null }));
29
vi.mock("../../../components/ui/FitSheet", () => ({
30
FitSheet: ({ children }: { children: ReactNode }) => children,
@@ -29,8 +37,15 @@ vi.mock("../../../components/ui/FormSection", () => ({
37
return null;
38
},
39
}));
32
-vi.mock("../../../components/ui/ListSection", () => ({ ListSection: () => null }));
33
-vi.mock("../../../components/ui/ListChoiceRow", () => ({ ListChoiceRow: () => null }));
40
+vi.mock("../../../components/ui/ListSection", () => ({
41
+ ListSection: ({ children }: { children: ReactNode }) => children,
42
+}));
43
+vi.mock("../../../components/ui/ListChoiceRow", () => ({
44
+ ListChoiceRow: (props: ActionProps) => {
45
+ state.actions.set(props.label, props);
46
+ return null;
47
+ },
48
+}));
49
vi.mock("../../../state/query", () => ({
50
useEnvironmentQuery: () => ({
51
data: state.refName === null ? undefined : { refName: state.refName },
@@ -49,7 +64,7 @@ vi.mock("../../../state/use-selected-thread-worktree", () => ({
64
}));
65
vi.mock("../../../state/use-selected-thread-git-state", () => ({
66
useSelectedThreadGitState: () => ({
52
- selectedThreadBranches: [],
67
+ selectedThreadBranches: [{ name: "release/stable", worktreePath: null }],
68
selectedThreadBranchesLoading: false,
69
gitOperationLabel: null,
70
}),
@@ -57,9 +72,11 @@ vi.mock("../../../state/use-selected-thread-git-state", () => ({
72
vi.mock("../../../state/use-selected-thread-git-actions", () => ({
73
useSelectedThreadGitActions: () => ({
74
canChangeThreadBranch: true,
60
- onCreateSelectedThreadWorktree: async (input: { baseBranch: string; newBranch: string }) => {
75
+ onCreateSelectedThreadBranch: () => state.gitResult,
76
+ onCheckoutSelectedThreadBranch: () => state.gitResult,
77
+ onCreateSelectedThreadWorktree: (input: { baseBranch: string; newBranch: string }) => {
78
state.worktrees.push(input);
62
- return null;
79
+ return state.gitResult;
80
},
81
}),
82
}));
@@ -80,6 +97,9 @@ function setup(branch: string | null = null) {
97
state.inputs.clear();
98
state.actions.clear();
99
state.worktrees = [];
100
+ state.gitResult = Promise.resolve(null);
101
+ state.focused = true;
102
+ state.goBackCalls = 0;
103
const root = createRoot(document.createElement("div"));
104
const render = () =>
105
act(() => {
@@ -92,12 +112,12 @@ function setup(branch: string | null = null) {
112
render();
113
return {
114
render,
115
+ press(label: string) {
116
+ act(() => state.actions.get(label)!.onPress());
117
+ },
118
edit(label: string, value: string) {
119
act(() => state.inputs.get(label)!.onChangeText(value));
120
},
98
- create() {
99
- act(() => state.actions.get("Create worktree")!.onPress());
100
- },
121
[Symbol.dispose]() {
122
act(() => root.unmount());
123
},
@@ -111,7 +131,7 @@ it.each([null, "stale-branch"])(
131
screen.edit("Worktree branch name", "feature/new-worktree");
132
state.refName = "release/stable";
133
screen.render();
114
- screen.create();
134
+ screen.press("Create worktree");
135
expect(state.worktrees).toEqual([
136
{ baseBranch: "release/stable", newBranch: "feature/new-worktree" },
137
]);
@@ -126,8 +146,27 @@ it.each(["custom-base", ""])("preserves an edited base %j when status arrives",
146
screen.render();
147
expect(state.inputs.get("Worktree base branch")!.value).toBe(base);
148
expect(state.actions.get("Create worktree")!.disabled).toBe(base === "");
129
- screen.create();
149
+ screen.press("Create worktree");
150
expect(state.worktrees).toEqual(
151
base === "" ? [] : [{ baseBranch: base, newBranch: "feature/new-worktree" }],
152
);
153
});
154
+
155
+it.each(["Create worktree", "Create & checkout", "release/stable"])(
156
+ "does not navigate back when %s finishes after the sheet lost focus",
157
+ async (action) => {
158
+ using screen = setup();
159
+ const gitResult = Promise.withResolvers<object>();
160
+ state.gitResult = gitResult.promise;
161
+ screen.edit("New branch name", "feature/new-branch");
162
+ screen.edit("Worktree branch name", "feature/new-worktree");
163
+ screen.press(action);
164
+ state.focused = false;
165
+
166
+ await act(async () => {
167
+ gitResult.resolve({ refName: "feature/ready" });
168
+ await gitResult.promise;
169
+ });
170
+ expect(state.goBackCalls).toBe(0);
171
+ },
172
+);
apps/mobile/src/features/threads/git/GitBranchesSheet.tsx
+3
-3
@@ -83,7 +83,7 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
83
const branch = sanitizeFeatureBranchName(newBranchName.trim());
84
if (branch.length === 0) return;
85
void gitActions.onCreateSelectedThreadBranch(branch).then((result) => {
86
- if (result === null) return;
86
+ if (result === null || !navigation.isFocused()) return;
87
setNewBranchName("");
88
navigation.goBack();
89
});
@@ -123,7 +123,7 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
123
void gitActions
124
.onCreateSelectedThreadWorktree({ baseBranch, newBranch })
125
.then((result) => {
126
- if (result === null) return;
126
+ if (result === null || !navigation.isFocused()) return;
127
setWorktreeBranchName("");
128
navigation.goBack();
129
});
@@ -161,7 +161,7 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
161
disabled={!canChangeThreadBranch || busy || disabled}
162
onPress={() => {
163
void gitActions.onCheckoutSelectedThreadBranch(branch.name).then((result) => {
164
- if (result === null) return;
164
+ if (result === null || !navigation.isFocused()) return;
165
navigation.goBack();
166
});
167
}}