question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: platform pause and resume subscriptions are outside Angular Zone

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:11
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
toxaqcommented, Apr 11, 2021

https://github.com/ionic-team/ionic-framework/issues/18342 Seems they don’t consider this to be an ionic problem…

… and oddly was “fixed” here in 2019 https://github.com/ionic-team/ionic-framework/issues/18831 despite still being a problem in 2021…

0reactions
toxaqcommented, Apr 11, 2021

But how would capacitor help here?

Depends on what you consider the problem to be. If it’s inconsistent behaviour and general lack of fixes in the Ionic Angular package then by using capacitor directly, you no longer need to be dependent on a bridge between capacitor or cordova via a service in Ionic Angular. Just write your own Platform service that picks up the capacitor evens and wrap your own code in an ngZone.

It’s clear that Ionic is in a rush to divorce to itself from Angular and sadly it shows. Capacitor at least framework independent and easily wrapped for consumption.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: platform pause and resume subscriptions are outside ...
Current behavior: The code executed in response to platform pause and resume subject emitting is not executed in the Angular Zone. This causes ......
Read more >
Ionic: Platform pauze/resume subscriptions - Stack Overflow
Something strange is going on when platform.resume is triggered. After the iPhone app comes out of pause mode, the UI no longer updates ......
Read more >
Platform pauze/resume subscriptions - Ionic Framework
Something strange is going on when platform.resume is triggered. After the iPhone app comes out of pause mode, the UI no longer updates ......
Read more >
Halo Infinite Winter Update – November 8, 2022
Challenges listed on the pause menu during multiplayer matches will now show their correct XP values. Reintroduced the "Congratulations" message ...
Read more >
Sumo Logic Service Release Notes
Latest features and bug fixes for Sumo Logic apps, alerts, security, search, observability, data collectors, and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found