Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ngrx/store/init is Fired Twice (with sub-modules) #133

Closed
kesarion opened this issue Jul 20, 2017 · 9 comments
Closed

Ngrx/store/init is Fired Twice (with sub-modules) #133

kesarion opened this issue Jul 20, 2017 · 9 comments

Comments

@kesarion
Copy link

kesarion commented Jul 20, 2017

Possibly related to ngrx/store#280.

I'm getting @ngrx/store/init once for the app module and again for other modules; it doesn't seem to matter whether they're loaded eagerly or lazily (it's happening only when lazy loading now).

This wouldn't normally be a problem, but when you navigate from a page to one from another module, the re-init causes the last state to be sent again to all subscriptions, so in my case, for example, I have a subscription to new notifications and if there was a notification on the previous page I receive it again. That's not ok.

I extended the app store with a new reducer using store.addReducer(), store being a Store with an extended state. Everything else works as expected.

I'm also using the router-store, effects and store-devtools, all v4.*.

Is there any way around this issue?

Thanks!

@brandonroberts
Copy link
Member

Can you reproduce this in a plunker or repo? Thanks

@generalcss
Copy link

Just opened the example app, it console logs the "@ngrx/store/init" action 3 times.
So per feature I guess.Auth, Books and Layout. Is this desired behaviour?

@kesarion
Copy link
Author

kesarion commented Jul 31, 2017

@brandonroberts I think @generalcss is right, the example app will exhibit the same behaviour. I used StoreModule.forFeature() with my app and I had the same results.

I think the example app may be sufficient for reproducing the behaviour, but do you have a working v4 plunker I could modify?

@brandonroberts
Copy link
Member

@kesarion yes, there is a plunker link in the issue template: http://plnkr.co/edit/tpl:757r6L

@kesarion
Copy link
Author

kesarion commented Aug 3, 2017

@brandonroberts You were missing import { FormsModule } from '@angular/forms'; in app.ts :)

@jonasdaugalas
Copy link

Here is the plunker: http://plnkr.co/edit/GRUlzV8xMNsDsf0Jjb97

Personally, for me, the problem is dispatching an action before lazy loaded store is initialized, somehow this way the action is being handled twice. See src/app.component.ts line 27 - "ADD" action is dispatched once, but logging meta reducer logs that action twice (the second time is after lazy loaded store init) and, after everything settles, the state has two "things" instead of one.

Afterwards dispatching actions works as expected.

@karptonite
Copy link
Contributor

Hmm... I think this is directly related to this issue #229. Wish I'd seen it earlier!

@kesarion
Copy link
Author

kesarion commented Aug 4, 2017

@karptonite @brandonroberts I can confirm, this happens only with Devtools. Commenting out Devtools in the app module fixes the issue, which means this won't be an issue in production environments 😉

Since this is cleared up and will be handled in #229, I think we can close this one.

@kesarion kesarion closed this as completed Aug 4, 2017
@victorbadila
Copy link

this still happens with devtools thus it poses a problem when debugging during development. then the second init is fired the previous actions get completely wiped. I think this needs to be reopened

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants