Skip to content

Constant refresh caused by setTimeout() and addEventListener() #440

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

Closed
martin1cerny opened this issue Sep 27, 2018 · 5 comments
Closed

Constant refresh caused by setTimeout() and addEventListener() #440

martin1cerny opened this issue Sep 27, 2018 · 5 comments
Labels
future-version Will be considered, but for a future version. pr-welcome We'd welcome a PR to solve the issue.

Comments

@martin1cerny
Copy link
Contributor

First of all thank you @manfredsteyer for the great library which makes my life a lot easier!

I work on an Angular application and I recently came across the use of zone.js in Angular which is used to trigger view refresh on every event which could cause the UI to change. So, I started to investigate when our views are actually getting refreshed and I realised that angular-oauth2-oidc is causing it to refresh every 3000ms when it asks for the state of the session and than when it receives the response.

I tried to run the initialization code out of Angular like this:

zone.runOutsideAngular(() => {
    this.oauthService.configure(config);
    this.oauthService.tokenValidationHandler = new JwksValidationHandler();
});

zone.runOutsideAngular(() => {
    this.oauthService.loadDiscoveryDocument()
        .then(() => {
            this.zone.runOutsideAngular(() => {
                this.oauthService.tryLogin({
                    onTokenReceived: (info) => {
                        const state = info.state;
...

But setting silent refresh and session check happens in a different scope in asynchronous callbacks where zone.runOutsideAngular() doesn't seem to take effect.

I realised there are already parts of the code which run outside of Angular and I believe that as a library it should only cause a refresh when it emits new event (like session timeout, expired tokens etc.) but not when working internally. Am I right? Or is there a way to run it out of Angular completely?

@manfredsteyer
Copy link
Owner

This is a good point. Thanks for pointing this out. Do you care for a PR?

@manfredsteyer manfredsteyer added pr-welcome We'd welcome a PR to solve the issue. future-version Will be considered, but for a future version. labels Oct 5, 2018
@martin1cerny
Copy link
Contributor Author

I created PR shortly after the issue. And it is merged now I see :-) Thanks a lot for the great work!

@ampled
Copy link

ampled commented Oct 12, 2018

Is this far off from being included in a release?

@martin1cerny
Copy link
Contributor Author

I'm looking forward having this available on NPM as well.

@jeroenheijmans
Copy link
Collaborator

PR got merged and a few releases got out since as well. Closing the issue, let us know if it should be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future-version Will be considered, but for a future version. pr-welcome We'd welcome a PR to solve the issue.
Projects
None yet
Development

No branches or pull requests

4 participants