Repository navigation
fix(react-router): hide stale pages after a redirect from a pushed tab route - #31807
Open
AdityaxDeore wants to merge 1 commit into
Open
AdityaxDeore wants to merge 1 commit into
AdityaxDeore wants to merge 1 commit into
Conversation
…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 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #31709
Problem
When the app pushes a route in an
IonTabsoutlet 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.ionPageoutlet of the redirecting route is left visible on top. It is transparent, so the screen looks right, but it takes every click.Root cause
Both paths are in
StackManagerfor the tabs outlet. The push from Orange to/banana/redirectstarts one transition, and the redirect to/applestarts a second one in the same outlet before the first is done.runCommitcallsrouterOutlet.commit(), which waits for the entering element before animating. The redirect (directionnone) swaps visibility synchronously: Apple is shown, Banana getsion-page-hidden. The firstcommit()then runs its animation, and core's transition un-hides its entering element (Banana) and hides its leaving element (Orange). After the commit,runCommitrepairs a stale hide of the newer transition's page, but nothing re-hides the stale transition's own entering page.routeInfo.lastPathname(/banana/redirect). That view has no page element, sotransitionPagegets no leaving view and hides nothing; Orange stays visible.Fix
In
packages/react-router/src/ReactRouter/StackManager.tsx:runCommit, mirror the existing stale-hide repair — after it re-showsleavingElwhen 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).hideOtherVisibleViews(), called fromhandleReadyEnteringViewjust beforetransitionPage: 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 inhandleWaitingForIonPage(the Navigate branch and theionPageWaitTimeoutpath), 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.tswith test pageredirect-stale-commit: IonTabs with Apple / Orange / BananaionPageoutlets; Banana's only childredirectrenders<Navigate replace to=".../apple" />afterdelayms, or immediately when its "Redirect now" button is pressed.Fail-before on the unfixed build: path A failed reliably (Banana outlet stayed visible, class
hydrated ion-page can-go-back, noion-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-routerbuild passes.Related: this PR includes the same
hideOtherVisibleViewshelper 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.