Skip to content

Session check changed to run outside of Angular zone #441

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

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,22 +935,30 @@ export class OAuthService extends AuthConfig {
);
}

// only run in Angular zone if it is 'changed' or 'error'
switch (e.data) {
case 'unchanged':
this.handleSessionUnchanged();
break;
case 'changed':
this.handleSessionChange();
this.ngZone.run(() => {
this.handleSessionChange()
});
break;
case 'error':
this.handleSessionError();
this.ngZone.run(() => {
this.handleSessionError()
});
break;
}

this.debug('got info from session check inframe', e);
};

window.addEventListener('message', this.sessionCheckEventListener);
// prevent Angular from refreshing the view on every message (runs in intervals)
this.ngZone.runOutsideAngular(() => {
window.addEventListener('message', this.sessionCheckEventListener);
});
}

private handleSessionUnchanged(): void {
Expand Down Expand Up @@ -1029,10 +1037,12 @@ export class OAuthService extends AuthConfig {

private startSessionCheckTimer(): void {
this.stopSessionCheckTimer();
this.sessionCheckTimer = setInterval(
this.checkSession.bind(this),
this.sessionCheckIntervall
);
this.ngZone.runOutsideAngular(() => {
this.sessionCheckTimer = setInterval(
this.checkSession.bind(this),
this.sessionCheckIntervall
);
});
}

private stopSessionCheckTimer(): void {
Expand Down