Skip to content

fix: run Keycloak token refresh outside Angular zone to avoid unnecessary change detection - #2166

Merged
lbroudoux merged 2 commits into
microcks:masterfrom
Harishrs2006:fix/keycloak-token-refresh-outside-ngzone
Jun 25, 2026
Merged

lbroudoux merged 2 commits into
microcks:masterfrom
Harishrs2006:fix/keycloak-token-refresh-outside-ngzone

Conversation

@Harishrs2006

Copy link
Copy Markdown
Contributor

Summary

  • Wrapped the periodic setInterval token refresh in NgZone.runOutsideAngular()
  • Prevents Angular from triggering change detection every 30 seconds when no UI state has changed
  • Added NgZone as a constructor dependency in KeycloakAuthenticationService

Changes
webapp/src/main/webapp/src/app/services/auth-keycloak.service.ts

Test plan

  • Login to Microcks with Keycloak auth enabled
  • Verify token still refreshes correctly after 30 seconds
  • Verify no unnecessary Angular change detection cycles triggered during idle time

Fixes #2124

…sary change detection

Wrapping the periodic token refresh setInterval in NgZone.runOutsideAngular()
prevents Angular from triggering change detection every 30 seconds when
no UI-relevant state has changed.

Fixes microcks#2124

Signed-off-by: Harishrs2006 <[email protected]>
AuthenticationServiceFactory was manually instantiating the service
without the NgZone argument, causing a build failure. Updated the
factory function and deps array to include NgZone.

Signed-off-by: Harishrs2006 <[email protected]>

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks all good. Thanks for pushing this.

@lbroudoux
lbroudoux merged commit fcce6ac into microcks:master Jun 25, 2026
11 of 12 checks passed
lbroudoux pushed a commit that referenced this pull request Aug 5, 2026
…sary change detection (#2166)

* fix: run Keycloak token refresh outside Angular zone to avoid unnecessary change detection

Wrapping the periodic token refresh setInterval in NgZone.runOutsideAngular()
prevents Angular from triggering change detection every 30 seconds when
no UI-relevant state has changed.

Fixes #2124

Signed-off-by: Harishrs2006 <[email protected]>

* fix: pass NgZone to KeycloakAuthenticationService in factory provider

AuthenticationServiceFactory was manually instantiating the service
without the NgZone argument, causing a build failure. Updated the
factory function and deps array to include NgZone.

Signed-off-by: Harishrs2006 <[email protected]>

---------

Signed-off-by: Harishrs2006 <[email protected]>
(cherry picked from commit fcce6ac)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize Keycloak token refresh by running it outside Angular zone

2 participants