Skip to content

fix(react-router): hide stale pages after a redirect from a pushed tab route - #31807

Open
AdityaxDeore wants to merge 1 commit into
ionic-team:mainfrom
AdityaxDeore:fix/31709-redirect-stale-commit
Open

AdityaxDeore wants to merge 1 commit into
ionic-team:mainfrom
AdityaxDeore:fix/31709-redirect-stale-commit

Conversation

@AdityaxDeore

Copy link
Copy Markdown

Fixes #31709

Problem

When the app pushes a route in an IonTabs outlet and that route immediately redirects (for example an auth guard that renders <Navigate replace to="/login" />), the tabs outlet can end up with two pages that are not hidden. No error is thrown and the URL is correct.

  • Path A: the redirect lands while the forward transition to the redirecting route is still running. The empty ionPage outlet of the redirecting route is left visible on top. It is transparent, so the screen looks right, but it takes every click.
  • Path B: the redirect lands before the redirecting route's page registers. The tab the user pushed from is never hidden.

Root cause

Both paths are in StackManager for the tabs outlet. The push from Orange to /banana/redirect starts one transition, and the redirect to /apple starts a second one in the same outlet before the first is done.

  • Path A: the push's runCommit calls routerOutlet.commit(), which waits for the entering element before animating. The redirect (direction none) swaps visibility synchronously: Apple is shown, Banana gets ion-page-hidden. The first commit() then runs its animation, and core's transition un-hides its entering element (Banana) and hides its leaving element (Orange). After the commit, runCommit repairs a stale hide of the newer transition's page, but nothing re-hides the stale transition's own entering page.
  • Path B: the leaving view is looked up from routeInfo.lastPathname (/banana/redirect). That view has no page element, so transitionPage gets no leaving view and hides nothing; Orange stays visible.

Fix

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

  • Path A: in runCommit, mirror the existing stale-hide repair — after it re-shows leavingEl when it equals the newer transition's entering element, re-hide this transition's entering element when a newer transition ran and is showing a different page. This is the fix proposed in the issue, verified by the reporter on the built 9.0.10 (12/12 runs at 10 ms and 20 ms).
  • Path B: add hideOtherVisibleViews(), called from handleReadyEnteringView just before transitionPage: when the transition has no leaving page element to hide, hide every other visible view in the outlet. This mirrors the hide-all-others fallback already in handleWaitingForIonPage (the Navigate branch and the ionPageWaitTimeout path), which the ready path was missing, and is the direction the issue proposes for path B.

Testing

New Playwright e2e spec packages/react-router/test/base/tests/e2e/playwright/redirect-stale-commit.spec.ts with test page redirect-stale-commit: IonTabs with Apple / Orange / Banana ionPage outlets; Banana's only child redirect renders <Navigate replace to=".../apple" /> after delay ms, or immediately when its "Redirect now" button is pressed.

  • Path A test pushes to Banana, then redirects manually once the Banana outlet is shown while Orange is still visible — i.e. while the forward transition is in flight — and asserts only Apple stays visible. The wait and the click both happen inside the page (requestAnimationFrame loop): the whole forward transition lasts only ~30 ms in this environment (measured with a MutationObserver) and a Playwright round-trip takes about as long, so a fixed millisecond delay never reproduced path A here (delays 0/10/50/100/200 ms all passed unfixed in single runs).
  • Path B test pushes with a 0 ms redirect delay and asserts only Apple stays visible.

Fail-before on the unfixed build: path A failed reliably (Banana outlet stayed visible, class hydrated ion-page can-go-back, no ion-page-hidden); path B failed 2 of 3 attempts in the original run. Pass-after: 2 passed in 3 consecutive runs. 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: this PR includes the same hideOtherVisibleViews helper as #31708 (PR #31806), because path B needs it and this branch is based on main. If #31708 merges first, this PR will be rebased to drop the duplicate helper; if this PR merges first, #31708 will be rebased the same way.

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

…b route

When the app pushes a route in an IonTabs outlet and that route
immediately redirects, the tabs outlet can end up with two pages that
are not hidden.

Path A: the redirect lands while the forward transition to the
redirecting route is still running. The redirect swaps visibility
synchronously, but the first commit() then runs its animation, and
core's transition un-hides its entering element (the redirecting
route's outlet). Mirror the existing stale-hide repair in runCommit:
when a newer transition ran and is showing a different page, re-hide
this transition's entering page.

Path B: the redirect lands before the redirecting route's page
registers, so the leaving view lookup finds a view with no page
element and transitionPage hides nothing, leaving the pushed-from tab
visible. 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. This mirrors the hide-all-others fallback already in
handleWaitingForIonPage, which the ready path was missing.

Regression test: Playwright e2e redirect-stale-commit.spec.ts. Path A
redirects manually while the forward transition is in flight (waited
and clicked inside the page, since the transition lasts only ~30 ms
here) and asserts only Apple stays visible; path B pushes with a 0 ms
redirect delay. Fail-before: path A failed reliably (Banana outlet
stayed visible), path B failed 2 of 3 attempts. Pass-after: 2 passed
in 3 consecutive runs. Neighbouring specs (ionpage-swipe-back,
hidden-view-renders, param-swipe-back): 9 passed.

Fixes ionic-team#31709
@AdityaxDeore
AdityaxDeore requested a review from a team as a code owner November 23, 2026 08:55
@AdityaxDeore
AdityaxDeore requested a review from thetaPC November 23, 2026 08:55
@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.

@github-actions github-actions Bot added the package: react @ionic/react package label Nov 23, 2026

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

Development

Successfully merging this pull request may close these issues.

bug: react-router, redirecting from a pushed tab route leaves a second tab outlet visible on top

1 participant