ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
50.98k stars 13.52k forks source link

bug: IonNav.canGoBack() sometimes throws exception: "Cannot read property 'apply' of undefined" #20721

Closed BorntraegerMarc closed 4 years ago

BorntraegerMarc commented 4 years ago

Bug Report

Ionic version:

[x] 4.11.10

Current behavior:

I'm experiencing an exception when using local notifications in an ionic native application. The exception only happens sometimes and I was not able to come up with exact reproduction steps. I wanted to open this bug because maybe someone can help me to point to the right direction so I can come up with exact reproduction steps for this ionic bug.

Basically what happens is that the user receives a notification (while app is in foreground) and then he sends the app to background. After waiting for like 10-30mins he clicks on the notification (while the app is still in background; so not a cold start). By clicking on the notification we check whether we need to pop any existing view before showing the new one with await this.chatRoomNavService.nav.canGoBack(). This produces the following exception: vendor-es2015.js: Line 52957 : ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined:

Screenshot 2020-03-06 at 09 37 27 (1)

Expected behavior:

No exception happens.

Steps to reproduce:

No clear reproduction steps available unfortunately. We were able to reproduce this bug mostly when app got sent to background for about 10-30mins & the phone screen got locked before clicking on the notification.

Related code:

In app.component:
```js
async ngOnInit() {
    await this.platform.ready();
    // Omitted code to simplify example

    this.localNotifications.on('click').subscribe(async (not: ILocalNotification) => {
        // Omitted code to simplify example
        this.chatService.chatInfoOpened.next(false);
    });
}

chat-room-nav.component:

ngOnInit() {
    this.chatService.chatInfoOpened.subscribe(async opened => {
        if (opened) {
            // Omitted code to simplify example
        } else {
            // Omitted code to simplify example
            if (await this.chatRoomNavService.nav.canGoBack()) {
                await this.chatRoomNavService.nav.pop();
            }
        }
    });
}

Other information:

Please note that the examples were significantly simplified so they are understandable.

Linking this issue to https://github.com/ionic-team/ionic/issues/20720 as they are related (both happens in the same scenario)

Ionic info:

Ionic:

   Ionic CLI                     : 6.2.0 (/Users/borntraegermarc/.nvm/versions/node/v12.13.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 4.11.10
   @angular-devkit/build-angular : 0.803.23
   @angular-devkit/schematics    : 8.3.23
   @angular/cli                  : 8.3.23
   @ionic/angular-toolkit        : 2.1.2

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 24 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 0.3.0

System:

   ios-sim : 8.0.2
   NodeJS  : v12.13.0 (/Users/borntraegermarc/.nvm/versions/node/v12.13.0/bin/node)
   npm     : 6.14.2
   OS      : macOS Catalina
   Xcode   : Xcode 10.3 Build version 10G8
liamdebeasi commented 4 years ago

Thanks for the issue. Can you provide a repo with the code required to reproduce this issue? I realize the issue states this only happens certain times, but without a code reproduction/steps to reproduce I am not sure I can be much help.

BorntraegerMarc commented 4 years ago

Thanks for your answer @liamdebeasi

Understood. So this confirms my suspicion that this is not a "straightforward" issue. Even for ionic experts :)

Please give us time until end of the week to come up with a simple repo with reproduction steps.

BorntraegerMarc commented 4 years ago

OK, we were also able to reproduce this bug with a minimal repository. Checkout master of: https://github.com/komed-health/ion-nav-bug-test

See screenshot of the exception here:

Screen Shot 2020-03-12 at 2 19 56 PM

For reproduction:

I think this bug relates somehow to https://github.com/ionic-team/ionic/issues/20720

BorntraegerMarc commented 4 years ago

@liamdebeasi were you able to reproduce the bug? Can I assist you in any way?

BorntraegerMarc commented 4 years ago

As discussed in the other issue. This workaround solves the bug: https://github.com/ionic-team/ionic/issues/20720#issuecomment-606247668

liamdebeasi commented 4 years ago

Closing as per https://github.com/ionic-team/ionic/issues/20720#issuecomment-606852036

ionitron-bot[bot] commented 4 years ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.