mauriciovigolo / keycloak-angular

Easy Keycloak setup for Angular applications.
MIT License
725 stars 278 forks source link

HMR not working #317

Open CedricBojoly opened 3 years ago

CedricBojoly commented 3 years ago

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search for issues before submitting
- [ ] feature request

Versions.

keycloak-angular 8.1.0 keycloak 11.0.3

Repro steps.

input field value is not restored.

if you remove the keycloak.init method call from initializeKeycloak and just return true everything works as intended. The input field value is restore if you change something on app.component.html

The log given by the failure.

Desired functionality.

If you make some changes on your source code but already have entered some values in an input field the value of the input field should be restored.

Bbemol commented 3 years ago

Reproduced here too. This bug is clearer now that angular 11 update has HMR native support.

Waterstraal commented 3 years ago

I would really like to enable HMR, but this bug is preventing me from do so.

fellmann commented 2 years ago

I found a very hacky solution, that apparently works. Add to initializeKeycloak:

function initializeKeycloak(keycloak: KeycloakService) {
  return () => {
    if (!environment.production) {
      if ((window as any).keycloak) {
        Object.assign(keycloak, (window as any).keycloak);
        return true;
      } else {
        (window as any).keycloak = keycloak;
      }
    }

    return keycloak.init({
      // ...
    });
  };
}

Still, this ticket is almost one year old, and the project has more than 45.000 downloads per week, so I would expect official support for HMR.