Skip to content

Commit 9d3aac8

Browse files
committed
fix(mobile): preserve chat history through PR self-links
1 parent 001a470 commit 9d3aac8

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎apps/mobile/src/lib/android-workspace-navigation.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,16 @@ it.each([false, true])(
395395
expect(selectTab).not.toHaveBeenCalled();
396396
},
397397
);
398+
399+
it("keeps chat history when a PR links to itself", async () => {
400+
current = withThread();
401+
const chat = current.routes;
402+
await useOpenPullRequest()("https://github.com/owner/repository/pull/42");
403+
const previous = current.routes;
404+
await useOpenPullRequest()("https://github.com/owner/repository/pull/42");
405+
useAndroidWorkspaceBack("pullRequests")();
406+
expect(current.routes).toEqual(previous);
407+
useAndroidWorkspaceBack("pullRequests")();
408+
expect(current.routes).toEqual(chat);
409+
expect(selectTab).not.toHaveBeenCalled();
410+
});

‎apps/mobile/src/lib/android-workspace-navigation.ts‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
import type { NavigationState } from "@react-navigation/native";
22
import { resetRootStack, type RootStackNavigation } from "./root-stack-reset";
33

4-
const detailIdentity = {
5-
Thread: ["environmentId", "threadId"],
6-
PullRequest: ["environmentId", "projectId", "repository", "number", "host"],
7-
} as const;
8-
9-
// Back returns to the detail a chat, PR, or subagent was opened from. A copy of the current
10-
// detail directly below it, which confirming a Git action from the inline inspector can leave,
11-
// is not a destination, so Back returns to the list instead.
124
function androidWorkspaceBackReturnsToDetail(state: NavigationState) {
135
const current = state.routes[state.index];
146
const previous = state.routes[state.index - 1];
157
if (current?.name !== "Thread" && current?.name !== "PullRequest") return false;
16-
if (previous?.name === "PullRequestFile") return true;
17-
if (previous?.name !== "Thread" && previous?.name !== "PullRequest") return false;
18-
if (current.name !== previous.name) return true;
19-
const currentParams = current.params as Readonly<Record<string, unknown>> | undefined;
20-
const previousParams = previous.params as Readonly<Record<string, unknown>> | undefined;
21-
return detailIdentity[previous.name].some(
22-
(key) => currentParams?.[key] !== previousParams?.[key],
23-
);
8+
if (previous?.name === "PullRequest" || previous?.name === "PullRequestFile") return true;
9+
if (previous?.name !== "Thread") return false;
10+
if (current.name === "PullRequest") return true;
11+
// Git actions can leave a duplicate Thread route that should return to its list.
12+
const params = current.params as ReactNavigation.RootParamList["Thread"] | undefined;
13+
return params !== undefined && !parentThreadIsBelow(state, params);
2414
}
2515

2616
/** The root stack with only the workspace list. */

0 commit comments

Comments
 (0)