Skip to content

bug: platform pause and resume subscriptions are outside Angular Zone #19539

Description

@Katur7

Bug Report

Ionic version:
[x] 4.7.1

Current behavior:
The code executed in response to platform pause and resume subject emitting is not executed in the Angular Zone. This causes Angular not to pick up any changes made.
So if the code updates something that is for example shown on a page it will not be updated until something else causes the change detection to pick it up.

Expected behavior:
That updates is response to the pause and resume events would be detected by Angular as it did in version 3

Steps to reproduce:

  • Create new Ionic app
  • Subscribe to the pause and resume events and console log NgZone.isInAngularZone()

Related code:
https://github.com/Katur7/ionic-platform-events
The relevant changes in src/app/app.component.ts

Other information:
This affected my app because I was disconnecting a websocket connection to our streamer on the pause event and reconnecting on resume. After reconnecting the changes were not shown until after clicking something in the app.

I fixed it by adding this.ngZone.run around the code

this.platform.resume.subscribe(() => this.ngZone.run(() => {
  // code
}));

I also have a subscription to the onConnect() observable from the @ionic-native/network/ngx plugin that has the same issue.

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.2 (/home/grimur/.nvm/versions/node/v12.11.0/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.10.0
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.0.0

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.2, (and 4 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 0.2.8 

System:

   Android SDK Tools : 26.1.1 (/home/grimur/Android/Sdk/)
   NodeJS            : v12.11.0 (/home/grimur/.nvm/versions/node/v12.11.0/bin/node)
   npm               : 6.11.3
   OS                : Linux 4.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions