fix(mobile): Back from a PR opened in a chat returns to the chat on Android#27653

open2
main
GitHub fork: fix/android-pr-link-back-stack
opened10d agobyBbitmvk
View on GitHubTwo-way sync enabledPR last imported 1h ago

Fixes #24753. Replaces #27050, which was closed for missing before/after captures; those are below. The code is the same, rebased onto main. It is a smaller alternative to #18839: first-send behavior is untouched, and only links and Back change.

Problem

On Android, opening a PR from a chat (or a chat from a PR, or one stacked PR from another) replaced the whole stack, so Back landed on a list instead of the page you came from, and the next Back left the app. iOS already pushes these pages.

Cause and fix

Link callers took an Android-only selectDetail branch, which replaces the stack and switches the list tab. On top of that, PR and chat pages selected their own tab whenever they gained focus, and Back reset straight to the list.

diff
1 open PR/chat/stacked-PR link
2- android: selectDetail (replace stack, select tab)
3+ push (same as iOS)
4 PR/chat page focus
5- select "pullRequests" | "threads"
6 Back (toolbar or system)
7- reset to list unless a distinct thread is below
8+ go to the previous page, skipping duplicate copies of the same thread
9+ nothing below: reset to list
10 app cold-starts on a page (outside link)
11+ start on that page's list

The list tab now changes only when you tap a tab or a list row, so Back from a page returns to the list you came from.

Evidence

Android 16 emulator, system Back.

Before: Back from the PR skips the chat and lands on the Pulls list.

External image

After: Back returns to the chat, then to the Chats list.

External image

Pulls → PR → Work on PR → Back → Back

Before: Back from the new chat skips the PR and lands on the Chats list.

External image

After: Back returns to the PR, then to the Pulls list with Pulls still selected.

External image

The toolbar back arrow gave the same results when checked for #27050. Not tested on a device: stacked-PR links, because the test data has no stacked PRs, and cold-start links, because the dev client's launcher screen catches them before the app loads. Stacked PRs use the same push and Back path. If the cold-start tab weren't picked up, the list would start on Chats, as it does today.

android-workspace-navigation.test.ts, extended inside the existing Back test:

  • [Home, Thread, PR] → Back → [Home, Thread]. Fails on main, where it gives [Home].
  • [Home, T, child, child-copy] → Back → [Home, T]. Fails on main, where it gives [Home].

vp run check:changed passes.

Merge Danger

Door: two-way. It changes no data or contracts, and a revert restores the old behavior.

Blast Radius: small. Android's link and Back navigation only: iOS was already on the push path, and the shared Back hook keeps its iOS branch unchanged.

Fixed by Claude Opus 5.5 in Claude Code (T3 Code). First implementation by GPT-6.1-Sol (Codex). Reviewed by GLM-5.3 Flash; device pass partly run by DeepSeek V4.1 Flash.

🤖 Generated with Claude Code

Checks

22 successful · 8 skipped · 1 neutral
All checks passed
16377ba

Added 2 commits

  • fix(mobile): cold-start PR links start on the Pulls list on Android16377ba
  • fix(mobile): Back from a PR opened in a chat returns to the chat on Android274e973
Synced from GitHub

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — The change preserves Android chat/PR navigation history so Back returns to the originating page. It also changes cold-start PR links to select Pulls instead of Chats, requiring confirmation of that new initial-list behavior.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

External image Recent review info
External image Run configuration
External image Commits

Reviewing files that changed from the base of the PR and between 6575ce32508bd7908444241f3719aa33aaf77f90 and 16377baa9d47933961587bfb2afde9a693f93c91.

External image Files selected for processing: 14
  • apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
  • apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
  • apps/mobile/src/features/pull-requests/PullRequestStackCard.tsx
  • apps/mobile/src/features/pull-requests/usePullRequestThreads.ts
  • apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
  • apps/mobile/src/features/threads/ThreadHeader.tsx
  • apps/mobile/src/features/threads/ThreadRouteScreen.tsx
  • apps/mobile/src/features/workspace/AndroidWorkspaceTabsProvider.tsx
  • apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx
  • apps/mobile/src/features/workspace/useAndroidWorkspaceNavigation.ts
  • apps/mobile/src/features/workspace/workspace-tabs-state.ts
  • apps/mobile/src/lib/android-workspace-navigation.test.ts
  • apps/mobile/src/lib/android-workspace-navigation.ts
  • apps/mobile/src/native/useOpenPullRequest.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Android workspace tabs now derive from navigation routes. Pull-request and thread navigation push routes, and Android Back uses route history to return to a prior destination or the workspace list.

Changes: Android workspace navigation

Layer / File(s)Summary
Derive and initialize workspace tabs
apps/mobile/src/features/workspace/workspace-tabs-state.ts, apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx, apps/mobile/src/features/workspace/AndroidWorkspaceTabsProvider.tsx, apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
A shared route-name lookup maps routes to workspace tabs. The Android provider passes the active route's tab to the workspace-tab state initializer.
Push pull-request and thread routes
apps/mobile/src/features/pull-requests/PullRequestStackCard.tsx, apps/mobile/src/features/pull-requests/usePullRequestThreads.ts, apps/mobile/src/native/useOpenPullRequest.ts
Pull-request and thread entry points now push navigation routes instead of selecting workspace details on Android.
Navigate Back using route history
apps/mobile/src/lib/android-workspace-navigation.ts, apps/mobile/src/features/workspace/useAndroidWorkspaceNavigation.ts, apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx, apps/mobile/src/features/threads/NewTaskDraftScreen.tsx, apps/mobile/src/features/threads/ThreadHeader.tsx, apps/mobile/src/features/threads/ThreadRouteScreen.tsx, apps/mobile/src/lib/android-workspace-navigation.test.ts
Android Back finds a prior route, skips parent-thread routes when applicable, and goes back or resets the stack. Back-navigation hooks no longer select workspace tabs. Tests cover pull-request and thread route history cases.

Priority: External image Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

mermaid
1sequenceDiagram
2 participant AndroidBack
3 participant BackHook as useAndroidWorkspaceBack
4 participant WorkspaceNavigation as returnToAndroidWorkspaceList
5 participant NavigationStack
6 AndroidBack->>BackHook: Press Back
7 alt Keyboard is visible
8 BackHook->>BackHook: Dismiss keyboard
9 else Keyboard is hidden
10 BackHook->>WorkspaceNavigation: Handle workspace Back
11 WorkspaceNavigation->>NavigationStack: Find prior route
12 alt Prior route is immediately previous
13 WorkspaceNavigation->>NavigationStack: goBack
14 else Prior route is earlier in history
15 WorkspaceNavigation->>NavigationStack: Reset to target and truncate later routes
16 else No prior target
17 WorkspaceNavigation->>NavigationStack: Reset to workspace list
18 end
19 end

Suggested labels: bugfix, size:M

Suggested reviewers: t3dotgg, pixpmusic

Merge Risk: External image Minimal · up to 16377

The navigation changes have no identified merge-blocking risk.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely describes the Android Back-navigation fix for pull requests opened from chats.
Linked Issues checkPassedIssue [#24753] requires Android Back from a pull request opened from a thread to return to that thread. useNavigateToPullRequest now pushes PullRequest on Android instead of replacing the workspac…
Out of Scope Changes checkPassedThe changes remain within Android workspace navigation. The updates for chat links, stacked pull requests, duplicate thread routes, and cold-start tab selection support the same route-history and list…
Description checkPassedThe description is complete and focused. It explains the Android navigation problem, the cause and fix, linked issue, scope, verification results, evidence, limitations, and agent attribution. The tem…
Full details: Linked Issues check

Explanation

Issue [#24753] requires Android Back from a pull request opened from a thread to return to that thread. useNavigateToPullRequest now pushes PullRequest on Android instead of replacing the workspace detail. returnToAndroidWorkspaceList follows the previous route and resets only when no previous route exists. The Android navigation test covers [Home, Thread, PullRequest] and verifies that Back restores [Home, Thread]. The toolbar and system Back paths use the updated back navigation hook.

Full details: Out of Scope Changes check

Explanation

The changes remain within Android workspace navigation. The updates for chat links, stacked pull requests, duplicate thread routes, and cold-start tab selection support the same route-history and list-selection behavior described for issue [#24753]. The added tests verify this navigation behavior. No unrelated data, contract, or product-area changes are shown.

Full details: Description check

Explanation

The description is complete and focused. It explains the Android navigation problem, the cause and fix, linked issue, scope, verification results, evidence, limitations, and agent attribution. The template heading ## Change is replaced by ## Cause and fix, but the required change information is present.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.