ngrx / platform

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

Weird `component-store` initialization problem in route guards #3661

Open dzonatan opened 1 year ago

dzonatan commented 1 year ago

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

component-store

Minimal reproduction of the bug/regression with instructions

https://stackblitz.com/edit/angular-ivy-hupmyu?devToolsHeight=33&file=src/app/local-store.ts

In the console: Error: LocalStore has not been initialized yet. Please make sure it is initialized before updating/getting.

Minimal reproduction of the bug/regression with instructions

The use-case might seem weird but I still think it's a legit one and should not fail.

It feels like the bug has something to do with the queue scheduler. Although, the problem only appears under some conditions (having nested routes with guards) which can be seen in the Stackblitz example.

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

@ngrx/component-store: 14.3.2 @angular/core: 14.2.10

Other information

No response

I would be willing to submit a PR to fix this issue

amakhrov commented 1 year ago

This also happens to me without using get directly - when I call patchState serially a few times (inside a complicated observable pipe, which, I assume, executes queueScheduler somewhere). Looks like the root cause is the same