Skip to content

fix(mobile): the shell returns to a screen already on its stack - #32110

Merged
Jinwoo-H merged 2 commits into
mainfrom
jinwoo/mobile-shell-pops-to-open-screen
Oct 23, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
jinwoo/mobile-shell-pops-to-open-screen

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​119 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​154 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​148

Why

On a phone, leaving a host with the page's own "back to hosts" chevron didn't go back to Home. It opened a second Home on top. The old host page stayed mounted underneath, keeping its WebView and its live subscriptions to the desktop, and every round trip added another one. System Back from Home then landed on a stale host page.

Cause: inside the page, the chevron calls dismissTo('/'), but the page's router hands every route it doesn't serve to the shell as one navigate(href) message, and the shell always answered with push.

What changed

Before opening anything, the shell now checks its own navigation stack:

  • The href is already a screen below this one (same path and query): pop back to it, as system Back would.
  • The href is this screen: do nothing, so no duplicate copy gets stacked.
  • Anything else: unchanged. The wide-layout host-route dismissTo and the plain push work as before, and the overlay replace is untouched.

Another worktree or tab under the same route pattern has a different path or query, so it still pushes.

native-stack-return.ts is a pure walk over the navigation state that finds the match. The pop names its navigator and source route explicitly, because a screen's dispatch otherwise stamps its own key as the source, and the parent stack can't find that key and silently drops the pop. Only the device run caught that.

Compatibility

Nothing on the wire changes: the bridge message and the page side are untouched, so every desktop version works. This ships with the next app release. Older apps keep today's behavior.

Verification

Android emulator (emulator-5710), real app, paired to a headless desktop:

  • Before (main): each chevron round trip grew the stack, from [index] to [index, h, index] to [index, h, index, h, index]. System Back from Home landed on the stale host page.
  • After: three round trips in a row leave [index] each time, and Back from Home exits the app. This was re-run on the final commit with the temporary logging removed.

Tests:

  • native-stack-return.test.ts covers matching, current-screen, a different worktree under the same pattern, and nested navigators.
  • In host-area-leave-session.test.tsx, the phone case that previously expected a push (the pile-up) now expects a return, and it fails on main.

Checks: mobile tsc, full mobile vitest, check:code-quality:changed, oxlint/oxfmt, and the reliability gates.

Not verified on a device: tablet/wide layout (covered by harness tests), a cold deep link (verified by reading the source), and iOS.

Not in this PR

After a cold deep link, where the host page is the bottom screen, the page's chevron still pushes Home over the host page, the same as on main. Making that case replace instead is a possible follow-up.

The page's own "back to hosts" chevron calls dismissTo('/') inside the page, which the page's
router hands to the shell as one navigate message. The shell pushed every such href, so leaving
a host from its page left [Home, Host, Home] with the old host page still mounted (WebView and
live subscriptions), and every round trip stacked another one. System Back then walked back
through stale host pages.

The shell now reads the navigation container's state first: an href that is already a screen
below this one (same path and query) is popped back to, and an href that is this screen is
dropped. Anything else is pushed as before. The pop names its navigator and source route
explicitly, because a screen's dispatch otherwise stamps its own key as the source and a parent
stack that cannot find it drops the pop.

The wide host-route dismissTo stays for the hrefs this rule does not cover: a host route whose
query differs from the one below (the missing-worktree bounce), and a cold deep link with no host
route below to return to. Overlay replace is unchanged, and so is the bridge message.
…reen on the stack

The session screen clears paneKey with setParams({ paneKey: '' }), which leaves ?paneKey= on the
stack entry, so a later navigate to the plain session href found no match and pushed a duplicate.
Empty query values are now dropped when canonicalising, and the fragment is stripped since
expo-router keeps it as a param no href spells the same way.
@Jinwoo-H

Jinwoo-H commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Review follow-up (4c4b5e0): a query param cleared to empty (the session screen's paneKey: '') and a #fragment no longer stop a match, so those cases return to the open screen instead of stacking a duplicate. A new test covers the empty param and fails without the fix.

Known and accepted: router.push in expo-router 55 is queued until an effect, while the pop dispatches immediately. If the page sent two navigate messages in the same tick, the second could land before the first. The page sends one per tap, so this is not reachable from user input today.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d79077aa-c85f-4f8a-8c2e-c696c4428695
📥 Commits

Reviewing files that changed from the base of the PR and between d59a947 and 4c4b5e0.

📒 Files selected for processing: 3
  • mobile/src/mobile-web-shell/MobileWebShellScreen.tsx
  • mobile/src/mobile-web-shell/native-stack-return.test.ts
  • mobile/src/mobile-web-shell/native-stack-return.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • mobile/src/mobile-web-shell/MobileWebShellScreen.tsx

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

📝 Walkthrough

The mobile web shell now checks the native navigation stack before navigating to a non-overlay destination. It leaves navigation unchanged when the destination is current, pops to an earlier matching route, and retains the existing wide-layout host-route handling and push fallback when no match exists. New tests cover stack matching and host-route return behavior.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 4c4b5

No actionable merge-blocking risk is established for this navigation change.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description clearly explains the problem, implementation, compatibility, verification, and known limitations. However, it omits required template information, including the linked issue, visual pr… Add the linked issue under "Linked Issue". Add before-and-after visual proof, or write N/A with a brief reason if no visual or interaction change applies. Complete the required Testing, AI Disclosure, Review, Agent skill upstream boundary…
Docstring Coverage Warning Docstring coverage is 70.59% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly describes the main change: returning to a screen already present in the mobile shell stack.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the problem, implementation, compatibility, verification, and known limitations. However, it omits required template information, including the linked issue, visual proof or an explicit N/A explanation, and the checklist sections.

Resolution

Add the linked issue under "Linked Issue". Add before-and-after visual proof, or write N/A with a brief reason if no visual or interaction change applies. Complete the required Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections, including the applicable test and review confirmations.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant