Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular's ApplicationRef never fire "isStable = true" in Firefox because of pace-js #540

Open
dstj opened this issue Sep 30, 2022 · 2 comments

Comments

@dstj
Copy link

dstj commented Sep 30, 2022

Hi,

OK, it's a weird one, granted, but I'm at a loss... :/

Description

In Firefox, simply adding pace-js to the application causes Angular to never fire the ApplicationRef.isStable = true event. But, in Chrome, Edge, Brave, it fires like expected...

Reproduction

  1. Install the Angular CLI
  2. Create a new clean Angular app: ng new testapp
  3. Add the following in app.component.ts:
    constructor(appRef: ApplicationRef) {
        appRef.isStable
          .pipe(
            tap((isStable) => console.log('stable', isStable)),
            first((isStable) => isStable),
            take(1)
          )
          .subscribe(() => {
            console.log('******** Application is stable **********');
          });
      }
  4. Run ng serve and confirm the output (in Firefox)

[webpack-dev-server] Live Reloading enabled.
stable false
Angular is running in development mode. Call enableProdMode() to enable production mode.
stable true
******** Application is stable **********

  1. Add pace-js to the appliation: run ng add pace-js
  2. Modify angular.json to include the pace-js script:
            "scripts": [
              "node_modules/pace-js/pace.min.js"
            ]
  3. Run ng serve again and confirm the output (in Firefox)

[webpack-dev-server] Live Reloading enabled.
stable false
Angular is running in development mode. Call enableProdMode() to enable production mode.

Problem: The application never become "stable"! In Chrome and Edge, the isStable = true "event" is fired as expected.

The Angular doc about ApplicationRef says:

the application will never be stable if you start any kind of recurrent asynchronous task when the application starts (for example for a polling process, started with a setInterval, a setTimeout or using RxJS operators like interval);

I know the pace-js source code has setInterval and setTimeout in it, so it's probably related somehow, I don't know. Any ideas how to resolve this? And why only Firefox seems affected?

Tested with:

  • Angular v13.3.0
  • Firefox v105.0.1 (64-bit)
  • pace-js v1.2.4
@BlairMcClelland
Copy link

BlairMcClelland commented Nov 27, 2022

We've had reports of something that sounds very similar, with AngularJS and an older version of Pace
After seeing this and digging around in Pace.sources and seeing it was Pace.sources[3] that was just sitting at 20% I added eventLag: false to Pace.options and Firefox looks to be loading without issue now. Of course I now have to dig into what changing that might break..

Edit - setting lagThreshold looks like the optimal change
#62 (comment)

@dstj
Copy link
Author

dstj commented Nov 28, 2022

@BlairMcClelland
Thanks for the information. I looked at the linked comment and tried to play with eventLag.lagTreshold. Adding this code to main.ts seems to work (though I have no idea about any possible side-effect of changing eventLag.lagThreshold).

declare var Pace: any;
Pace.options.eventLag.lagThreshold = 12;

Note:

  • Pace.options.eventLag.lagThreshold = 10; does NOT work
  • Pace.options.eventLag.lagThreshold = 11 works, but much slower than 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants