Skip to content

fix(react-router): hide preserved page when re-entering an ionPage outlet at a different page - #31806

Open
AdityaxDeore wants to merge 1 commit into
ionic-team:mainfrom
AdityaxDeore:fix/31708-swipe-preserved-page-visible
Open

AdityaxDeore wants to merge 1 commit into
ionic-team:mainfrom
AdityaxDeore:fix/31708-swipe-preserved-page-visible

Conversation

@AdityaxDeore

Copy link
Copy Markdown

Fixes #31708

Problem

In iOS mode, an ionPage child outlet can end up with two visible pages. The page that was active when the user left the outlet (Step 2) is never hidden, so when the user later returns to a different page in the same outlet (Step 1), the old page stays on screen and covers the new one. The URL is correct and no error is thrown. In md mode the same navigation works.

Root cause

StackManager.handleOutOfScopeOutlet has a branch for ionPage outlets whose parent outlet has swipeGesture === true (iOS mode default): when the outlet goes out of scope it keeps every child view mounted so a swipe back can show them, and returns without hiding the active child page. When the outlet comes back in scope at a different child route, the leaving view lookup misses (both routeInfo.lastPathname and routeInfo.prevRouteLastPathname belong to the parent outlet), so the transition shows the entering page and hides nothing. The extra Settings step matters: with only one outside navigation, prevRouteLastPathname still points at Step 2, so it is found as the leaving view and hidden.

Fix

In packages/react-router/src/ReactRouter/StackManager.tsx:

  • New hideOtherVisibleViews(enteringViewItem, leavingViewItem): hides every other visible, mounted view in the outlet — except the entering view, the leaving view (transitionPage hides it), and container routes when entering a container route (mirrors cleanupOrphanedSiblingViews). It runs only when the transition has no leaving page element to hide.
  • Called in handleReadyEnteringView just before transitionPage, after all duplicate/skip-transition early returns, so swipe-back gestures (which return early there and have a leaving element) are unaffected.

This mirrors the hide-all-others fallback already in handleWaitingForIonPage (the Navigate branch and the ionPageWaitTimeout path), which the ready path was missing.

Testing

New Playwright e2e spec packages/react-router/test/base/tests/e2e/playwright/swipe-preserved-page.spec.ts with test page swipe-preserved-page, reproducing the issue steps exactly (Step 1 → Step 2 → Home → Settings → Step 1, all router.push(path, 'forward'), iOS mode). It asserts the URL, Step 1 visible, and Step 2 carrying ion-page-hidden.

Fail-before on the unfixed build: Step 2 stayed visible (class ion-page can-go-back, no ion-page-hidden). Pass-after: 1 passed. Neighbouring specs on the fixed build — ionpage-swipe-back (2), hidden-view-renders (3), param-swipe-back (4): 9 passed.

Typecheck, eslint and prettier are clean; the @ionic/react-router build passes.

Related: the same helper also fixes #31709 path B (a redirect landing before the intermediate route's page registers leaves the pushed-from tab visible — the same no-leaving-element case). That issue additionally needs a runCommit re-hide for its path A, which is a separate PR.

Disclosure: AI coding assistance was used in preparing this change.

…tlet at a different page

In iOS mode, handleOutOfScopeOutlet preserves an ionPage outlet's child
views when the outlet goes out of scope so a swipe back can show them,
but it does not hide the active child page. When the outlet comes back in
scope at a different child route, the leaving view lookup misses (both
lastPathname and prevRouteLastPathname belong to the parent outlet), so
the transition shows the entering page and hides nothing, leaving the
preserved page visible on top of the new one.

Add hideOtherVisibleViews(), called from handleReadyEnteringView just
before transitionPage: when the transition has no leaving page element
to hide, every other visible view in the outlet is hidden (except the
entering view and container routes when entering a container route).
This mirrors the hide-all-others fallback already in
handleWaitingForIonPage, which the ready path was missing. The leaving
view is excluded because transitionPage hides it, and the call sits
after the duplicate/skip-transition early returns, so swipe-back
gestures are unaffected.

Regression test: Playwright e2e swipe-preserved-page.spec.ts reproduces
the issue steps (Step 1 -> Step 2 -> Home -> Settings -> Step 1, all
forward pushes, iOS mode) and asserts Step 2 is hidden. Fail-before:
Step 2 stayed visible (class 'ion-page can-go-back', no
ion-page-hidden). Pass-after: 1 passed. Neighbouring specs
(ionpage-swipe-back, hidden-view-renders, param-swipe-back): 9 passed.

Fixes ionic-team#31708
@AdityaxDeore
AdityaxDeore requested a review from a team as a code owner November 23, 2026 08:39
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@AdityaxDeore is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

Labels

package: react @ionic/react package

Projects

None yet

1 participant