ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
8.05k stars 1.98k forks source link

Effect initialised before APP_INITIALIZER in Angular v14 #3659

Closed diegovsil closed 2 years ago

diegovsil commented 2 years ago

Which @ngrx/* package(s) are the source of the bug?

effects

Minimal reproduction of the bug/regression with instructions

In angular v14 when effects are used together with APP_INITIALIZER any service used in these effects is initialized before APP_INITIALIZER, therefore any configuration that is retrieved with APP_INITIALIZER and is necessary for any service of these effects will not be available.

In angular v13, it worked correctly, any service used in an effect was initialized after APP_INITIALIZER.

Example working properly in angular 13 => stackblitz v13 Example working wrong in angular 14 => stackblitz v14

In the console can be seen the differences between both versions.

If the effectsModule is removed from the app.module imports, everything works properly again in version 14

Expected behavior

Any services used in the effects should be initialized after the APP_INITIALIZER

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

NgRx:14 Angular: 14 Node: 16.13.1 Browser: Chrome

hizliemre commented 2 years ago

This bug brings us too many troubles for us too. I am watching!

Did you read these comments? => #931

diegovsil commented 2 years ago

This bug brings us too many troubles for us too. I am watching!

Did you read these comments? => #931

yes, I had already read it, the fact is that somehow it was fixed in version 13, or maybe a previous one, but with version 14 of angular works wrong again

hizliemre commented 2 years ago

It can be related angular new feature named ENVIRONMENT_INITIALIZER. I am not sure. We should focus on that part.

timdeschryver commented 2 years ago

Please use the solution provided in #931, this still works

https://stackblitz.com/edit/angular-ivy-wzemdw?file=src/app/app.module.ts

EverettZ commented 1 year ago

Should this really be closed? Is this a feature gap, or a bug? If it's a feature gap, is there a roadmap that covers this? If it's a bug, why close these app init related bugs?

alex-okrushko commented 1 year ago

Hi @EverettZ Here's another solution for Effects to wait for app_init based on "runtime feature flag".

We are considering to add a utility to do something like this into the codebase.

carlokid commented 1 year ago

Please use the solution provided in #931, this still works

https://stackblitz.com/edit/angular-ivy-wzemdw?file=src/app/app.module.ts

There still an issue about this. See https://github.com/ngrx/platform/issues/931#issuecomment-381436562