Skip to content

Commit cc1eb02

Browse files
committed
fix(navcontrollerbase): fixes crash when it is destroyed
fixes #11338
1 parent 5311336 commit cc1eb02

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/navigation/nav-controller-base.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ export class NavControllerBase extends Ion implements NavController {
216216
}
217217

218218
_success(result: NavResult, ti: TransitionInstruction) {
219+
if (this._queue === null) {
220+
this._fireError('nav controller was destroyed', ti);
221+
return;
222+
}
219223
this._init = true;
220224
this._trnsId = null;
221225

@@ -237,6 +241,10 @@ export class NavControllerBase extends Ion implements NavController {
237241
}
238242

239243
_failed(rejectReason: any, ti: TransitionInstruction) {
244+
if (this._queue === null) {
245+
this._fireError('nav controller was destroyed', ti);
246+
return;
247+
}
240248
this._trnsId = null;
241249
this._queue.length = 0;
242250

@@ -245,6 +253,10 @@ export class NavControllerBase extends Ion implements NavController {
245253
this._swipeBackCheck();
246254
this._nextTrns();
247255

256+
this._fireError(rejectReason, ti);
257+
}
258+
259+
_fireError(rejectReason: any, ti: TransitionInstruction) {
248260
if (ti.done) {
249261
ti.done(false, false, rejectReason);
250262
}

src/navigation/test/nav-controller.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,23 @@ describe('NavController', () => {
10681068

10691069
});
10701070

1071+
describe('destroy', () => {
1072+
1073+
it('should not crash when destroyed while transitioning', (done) => {
1074+
let view1 = mockView(MockView1);
1075+
nav.push(view1).then(() => {
1076+
fail('it should not succeed');
1077+
done();
1078+
}).catch((err: any) => {
1079+
expect(err).toEqual('nav controller was destroyed');
1080+
done();
1081+
});
1082+
nav.destroy();
1083+
}, 10000);
1084+
1085+
});
1086+
1087+
10711088
let nav: NavControllerBase;
10721089
let trnsDone: jasmine.Spy;
10731090

0 commit comments

Comments
 (0)