platform icon indicating copy to clipboard operation
platform copied to clipboard

Effect initialised before APP_INITIALIZER in Angular v14

Open diegovsil opened this issue 4 years ago • 7 comments

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

diegovsil avatar Nov 10 '22 15:11 diegovsil

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

Did you read these comments? => #931

hizliemre avatar Nov 11 '22 11:11 hizliemre

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

diegovsil avatar Nov 11 '22 13:11 diegovsil

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

hizliemre avatar Nov 11 '22 14:11 hizliemre

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

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

timdeschryver avatar Nov 16 '22 18:11 timdeschryver

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?

EverettZ avatar Jul 26 '23 17:07 EverettZ

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.

alex-okrushko avatar Jul 26 '23 19:07 alex-okrushko

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

carlokid avatar Oct 28 '23 16:10 carlokid