bug: react-router, redirecting from a pushed tab route leaves a second tab outlet visible on top
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- react, typescript
- 领域
- frontend
调研方向
Start with packages/react-router/src/ReactRouter/StackManager.tsx, especially transitionPage, runCommit, and the ionPageWaitTimeout fallback. Trace both redirect timings in the linked reproduction: the proposed change addresses the stale animated commit, while the immediate redirect still leaves the previous tab visible. Done means both paths leave only the page for the current pathname visible; add or run focused React Router tests for both cases.
由索引模型根据 Issue 内容生成。
描述
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
v9.x
Current Behavior
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.
<ion-router-outlet class="apple-outlet ion-page can-go-back" style="z-index: 101;">…</ion-router-outlet>
<ion-router-outlet class="banana-outlet ion-page can-go-back" style="z-index: 101;"></ion-router-outlet>
Which page is left visible depends on how soon the redirect follows the push:
- Path A: the redirect lands while the forward transition to the redirecting route
is still running. The emptyionPageoutlet of the redirecting route is left visible
on top. It is transparent, so the screen looks right, but it takes every click: the
app stops responding to taps on the page, and after switching tabs, the other tab's
buttons cannot be pressed either. - Path B: the redirect lands before the redirecting route's page registers. The tab
the user pushed from is never hidden. It keeps noion-page-hiddenoraria-hidden.
In the reproduction it sits behind the new page and is cleared when that tab is
pressed again.
Expected Behavior
After the redirect, only the page for the current pathname is visible in the tabs
outlet. The redirecting route's outlet and the tab the user pushed from are both hidden.
Steps to Reproduce
- Clone the reproduction, check out
stale-commit-reshows-entering-page, then run
npm installandnpm run dev. - Open
/apple. The Apple tab is shown. - Press the Orange tab.
- Press Redirect after 10 ms. The app calls
router.push('/banana/redirect?delay=10', 'forward', 'push'). That route renders
<Navigate replace to="/apple" />after 10 ms. - Observe: the URL is
/appleand the Apple page is shown, but the status bar above the
tab bar reports10 ms: apple + banana (empty) ← BUG path A. Clicking the Apple page
hits the emptybanana-outletelement. Press the Orange tab: the Orange page is
shown, but its buttons do not respond. - Reload, then repeat steps 3–4 with Redirect after 0 ms. Observe:
0 ms: apple + orange (empty) ← BUG path B. The Orange outlet is not hidden.
Reload between tries, because path A leaves the page unable to take clicks.
How reliably it reproduces (Chromium, md mode, fresh load each try):
| Button | Result |
|---|---|
| Redirect after 0 ms | stale 10/10 runs: mostly path B, sometimes path A |
| Redirect after 10 ms | path A 5/5 runs |
| Redirect after 20 ms | path A 4/10 runs |
| Redirect after 50 ms | 5/5 runs correct (control: the transition finishes first) |
The timing window depends on the machine. If 10 ms does not show path A, try 0 ms or
20 ms.
The redirecting route must be an ionPage outlet. With a plain
<Route path="/banana/redirect" element={<Navigate … />} /> in the tabs outlet, every
run ends with only Apple visible. The route shape:
<IonRouterOutlet>
<Route path="*" element={
<IonTabs>
<IonRouterOutlet>
<Route path="/apple/*" element={<IonRouterOutlet ionPage>…</IonRouterOutlet>} />
<Route path="/orange/*" element={<IonRouterOutlet ionPage>…</IonRouterOutlet>} />
<Route path="/banana/*" element={
<IonRouterOutlet ionPage>
<Route path="redirect" element={<RedirectToApple />} />
</IonRouterOutlet>
} />
</IonRouterOutlet>
<IonTabBar slot="bottom">…</IonTabBar>
</IonTabs>
} />
</IonRouterOutlet>
Code Reproduction URL
https://github.com/ptmkenny/ionic-react-router-6-test/tree/stale-commit-reshows-entering-page
Ionic Info
Ionic:
Ionic CLI : 7.2.1 (/home/node/.npm/_npx/f6fddb685269761d/node_modules/@ionic/cli)
Ionic Framework : @ionic/react 9.0.10
Capacitor:
Capacitor CLI : 8.0.0
@capacitor/android : not installed
@capacitor/core : 8.0.0
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 2.0.1
System:
NodeJS : v26.13.0 (/usr/local/bin/node)
npm : 11.20.0
OS : Linux 6.18
Additional Information
I used AI (Opus 5.5) to prepare this issue report and reproduction.
Root cause
Names below refer to the three ionPage outlets in the reproduction's tabs outlet:
- Orange (
/orange/*): the tab the user is on when the app pushes. - Banana (
/banana/*): the pushed route. Its only child,redirect, redirects. - Apple (
/apple/*): the redirect target.
Both paths are in StackManager
(packages/react-router/src/ReactRouter/StackManager.tsx) 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: a superseded animated commit shows its entering page.
-
The push (direction
forward) callstransitionPagewith the Banana outlet entering
and the Orange outlet leaving. The transition animates, sorunCommitcalls
routerOutlet.commit(), which waits for the entering element to be ready before
animating. -
The redirect (direction
none) callstransitionPageagain, which increments
transitionGeneration. It does not animate, so it swaps visibility synchronously:
Apple is shown, and the Banana outlet getsion-page-hidden. -
The first
commit()then runs its animation. Core's transition un-hides its
entering element (the Banana outlet) and hides its leaving element (Orange). -
After the commit,
runCommitchecks for a newer transition:if (myGeneration !== this.transitionGeneration && leavingEl && leavingEl === this.transitionEnteringElement) { showIonPageElement(leavingEl); }That repairs a stale hide of the newer transition's page, but nothing re-hides the
stale transition's own entering page. The Banana outlet stays visible with
z-index: 101, on top of Apple.
Path B: the leaving view is looked up by the intermediate route.
- The push finds the Banana view, which has no page element yet, so
handlePageTransitionwaits for itsIonPage. - The redirect arrives before the Banana outlet registers. The Apple outlet is ready,
so the transition runs, but the leaving view is looked up from
routeInfo.lastPathname, which is/banana/redirect. That view has no page element,
sotransitionPagegets no leaving view and hides nothing. - The Orange outlet, which was visible before the push, is never hidden. Its child page
is unmounted later, which leaves it empty but still withoution-page-hidden.
The ionPageWaitTimeout fallback in handlePageTransition already handles this for an
entering view that never gets a page. Its comment says it hides all other views because
"intermediate redirects (e.g., Navigate in nested routes) change the leaving view
reference". The path where the entering view is ready has no equivalent.
The transitionGeneration check that path A gets past and the ionPageWaitTimeout
fallback that path B misses were both added with the react-router 6 upgrade (#30831).
Proposed fix
For path A, re-hide the entering page of a superseded commit unless the newer transition
is showing that same page:
if (myGeneration !== this.transitionGeneration && leavingEl && leavingEl === this.transitionEnteringElement) {
showIonPageElement(leavingEl);
}
+
+ /**
+ * A newer transitionPage call ran while this commit was in flight and showed a
+ * different page. The core commit has just made this transition's entering page
+ * visible, so hide it again.
+ */
+ if (myGeneration !== this.transitionGeneration && enteringEl !== this.transitionEnteringElement) {
+ hideIonPageElement(enteringEl);
+ }
Applied to the built @ionic/react-router 9.0.10 in the reproduction, the 10 ms and
20 ms buttons end with only Apple visible in 12/12 runs (6 at each delay). Unpatched,
path A shows in 5/5 runs at 10 ms and 4/10 at 20 ms. It does not affect path B: the
0 ms button still leaves Orange visible in 6/6 runs.
I have not written a fix for path B. A direction would be for the ready-entering-view
path to fall back the way the ionPageWaitTimeout path does when the leaving view
lookup finds no page: hide the other visible views in the outlet.
- 主要语言
- TypeScript
- 星标
- 52.8k
- 派生
- 13.3k
- 平均合并
- 3 天 1 小时
- 30 天内合并 PR
- 86
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ionic-team/ionic-framework 的其他 Issue
-
bug: input-otp, backspace in an empty box only moves focus instead of clearing the previous box可能已有人在做 @sarankumar1325 于 23 天前认领。 未关闭package: core type: bug
难度 2/5 1-3 小时 新手友好度 90/100
ionic-team/ionic-framework#31639 · 1 条评论 ·
维护者通常 1 天内回复
-
bug: vue swipe cancellation throws when the previous page is missing可能已有人在做 @dandoingdev 于 46 天前认领。 未关闭package: vue type: bug
难度 2/5 1-3 小时 新手友好度 78/100
ionic-team/ionic-framework#31514 · 1 条评论 ·
维护者通常 1 天内回复
-
bug: ion-searchbar input is always labelled "search text"; aria-label on the host is not forwarded可能已有人在做 @HappyKnuckles 于 41 天前认领。 未关闭a11y package: core type: bug
难度 2/5 1-3 小时 新手友好度 84/100
ionic-team/ionic-framework#31492 · 1 条评论 ·
维护者通常 1 天内回复
-
bug: IonTabs throws when a Fragment contains one IonRouterOutlet可能已有人在做 @Benziza 于 82 天前认领。 未关闭package: react type: bug
难度 2/5 1-3 小时 新手友好度 72/100
ionic-team/ionic-framework#31410 · 2 条评论 ·
维护者通常 1 天内回复
-
bug: angular swipe-back gesture crashes in StackController.startBackTransition when the stack is popped before the gesture is captured可能已有人在做 @officialasishkumar 于 9 天前认领。 未关闭package: angular type: bug
难度 2/5 1-3 小时 新手友好度 86/100
ionic-team/ionic-framework#31291 · 1 条评论 ·
维护者通常 1 天内回复
查看 ionic-team/ionic-framework 的全部 Issue
相似的 Issue
-
ready-for-ai
难度 1/5 1 小时以内 新手友好度 88/100
umbraco/Umbraco-CMS-MCP-Dev#647 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
HelloAOLab/seed-bible#2173 ·
维护者通常 1 天内回复
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100
hocinehacherouf/liberarr#77 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
LibreChat-AI/LibreChat#18225 ·
维护者通常 1 天内回复
-
b-ber/build/epub b-ber/themes
难度 2/5 1-3 小时 新手友好度 72/100
triplecanopy/b-ber#790 ·
维护者通常 1 天内回复