bug: angular swipe-back gesture crashes in StackController.startBackTransition when the stack is popped before the gesture is captured
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 86/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- angular, typescript
- Ambito
- frontend, mobile-dev
Direzione di ricerca
Inizia in packages/angular/common/src/directives/navigation/stack-controller.ts, in StackController.startBackTransition, quindi confronta la gestione dello stack con canStart in router-outlet.ts. Verifica il caso a vista singola descritto nei passaggi per la riproduzione e assicurati che uno swipe acquisito dopo l'estrazione dello stack diventi un no-op senza generare un'eccezione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
v8.x
Current Behavior
In production we consistently see this unhandled error coming from the iOS swipe-back gesture (Angular + Capacitor app, mode: 'ios'):
TypeError: Cannot read properties of undefined (reading 'animationBuilder')
at StackController.startBackTransition (@ionic/angular/fesm2022/ionic-angular-common.mjs)
Stack trace (from Sentry, @ionic/angular 8.7.17):
node_modules/@ionic/core/components/index3.js (pointerMove)
node_modules/@ionic/core/components/index3.js (tryToCapturePan)
node_modules/@ionic/core/components/index3.js (fireOnStart)
node_modules/@ionic/core/components/ion-router-outlet.js (onStart)
node_modules/@ionic/angular/fesm2022/ionic-angular-common.mjs (StackController.startBackTransition)
const customAnimation = enteringView.animationBuilder;
The root cause is a race between canStart and onStart of the swipe-back gesture:
canStartruns at pointer-down and checksthis.stackCtrl.canGoBack(1) && !this.stackCtrl.hasRunningTask()(https://github.com/ionic-team/ionic-framework/blob/b716c1cdacdd10a98c03f0c7fe6355182913be1d/packages/angular/common/src/directives/navigation/router-outlet.ts#L104-L108)onStartruns later, only once the pan gesture passes the capture threshold (pointerMove -> tryToCapturePan -> fireOnStart)
If a navigation pops the stack in that window (for example a programmatic navCtrl.back() finishing, a guard redirect, or a route replace), by the time onStart fires the stack contains a single view, so in startBackTransition views[views.length - 2] is undefined and the next line throws:
startBackTransition(): Promise<boolean> | Promise<void> {
const leavingView = this.activeView;
if (leavingView) {
const views = this.getStack(leavingView.stackId);
const enteringView = views[views.length - 2]; // undefined when the stack has 1 view
const customAnimation = enteringView.animationBuilder; // TypeError
Because it is a narrow timing window it is rare per user (almost always 1 event per user), but at our traffic volume it produces a steady stream of unhandled errors: roughly 200 events from about 200 users in the last 90 days, on both WebKit ("undefined is not an object (evaluating 'enteringView.animationBuilder')") and V8 ("Cannot read properties of undefined") engines. We have been seeing it continuously from Ionic 7 through 8.7.17, and the unguarded line is still present on current main.
Expected Behavior
When the entering view no longer exists at gesture-capture time, the swipe-back should be a no-op (same as when canStart returns false), not an unhandled TypeError, e.g.:
const enteringView = views[views.length - 2];
if (!enteringView) {
return Promise.resolve();
}
This would match every other consumer of the stack (canGoBack, pop, getLastUrl), all of which check the stack length before indexing into it.
Steps to Reproduce
The bug is a race, so it does not reproduce on every attempt, but the window can be hit with the standard Angular starter (blank template plus one pushed page) on an iOS device or simulator:
- Navigate from page A to page B (stack now has 2 views).
- Tap a button that calls
navCtrl.back()(or any navigation that pops/replaces the stack). - Immediately, before the back navigation completes, start a left-edge swipe and keep the finger moving.
- When the pan gesture is captured after the threshold,
onStartcallsstartBackTransition()on a stack that now has a single view and it throws.
The defect is also visible statically: startBackTransition guards leavingView but not enteringView.
Code Reproduction URL
No repository; the race is timing-dependent and fully explained by the linked source lines above (standard Angular starter + the steps from "Steps to Reproduce").
Ionic Info
Ionic:
@ionic/angular: 8.7.17
@ionic/core: 8.7.17
Angular: 20.3.25
Capacitor:
@capacitor/core: 8.3.3
Platforms: iOS and Android (Capacitor WebView, app runs in ios mode)
Additional Information
No response
- Lingua principale
- TypeScript
- Stelle
- 52.7k
- Fork
- 13.3k
- Merge medio
- 2g 20h
- PR unite (30g)
- 35
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ionic-team/ionic-framework
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ionic-team/ionic-framework#31410 · 1 commento ·
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ionic-team/ionic-framework#31314 ·
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ionic-team/ionic-framework#30738 ·
-
package: core type: bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
ionic-team/ionic-framework#29864 · 1 commento ·
-
package: core type: feature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
ionic-team/ionic-framework#29607 · 4 commenti · 1 reazione ·
Tutte le issue di ionic-team/ionic-framework
Issue simili
-
Browser Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
getsentry/sentry-javascript#24577 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
agilepathway/label-checker#640 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
copse-dev/agent-pane#2953 ·
-
[aw] Upgrade available Apertaagentic-workflows
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
githubnext/rig#534 ·
-
automation missing-model model-sync provider:pioneer
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
anomalyco/models.dev#7701 ·