Skip to content
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.

Ngrx/store/init is Fired Twice #280

Closed
JimLynchCodes opened this issue Nov 27, 2016 · 13 comments
Closed

Ngrx/store/init is Fired Twice #280

JimLynchCodes opened this issue Nov 27, 2016 · 13 comments

Comments

@JimLynchCodes
Copy link

This seems like a bug to me...

I have created a simple reducer which logs out the action that comes in:

import {ActionReducer, Action} from "@ngrx/store";
import {State, intitialState} from "../state/main-state";
import {INCREMENT, EVENT_FROM_EFFECT} from "../actions/main-action-creator";

export const mainReducer: ActionReducer<State> =
  (state = intitialState, action: Action) => {

    console.log('Action came in! ' + action.type);

  };

But when I test this is chrome I get the "init" action firing twice. Is there any good reason for firing it twice?

jimsngrxeg

@fxck
Copy link

fxck commented Nov 27, 2016

#256

@JimLynchCodes
Copy link
Author

I'm not really following the actual development of this, just trying to use it in my own project. And now that I know there is a "probe" event being fired as one of the "inits" I feel better about it so you can close this issue when it's fixed or when ever you feel like it. thanks

@jon301
Copy link

jon301 commented Dec 6, 2016

I have the same issue
It looks like 2 store instances are created (I see 2 instances in the dropdown menu in Redux DevTools)
This is problematic since the app binds to the 2nd one (which is empty because it initiliazes later) so you lose the state of the 1st one which may contains some data that could be loaded on app load

Any help is welcome
Thanks !

@qdouble
Copy link

qdouble commented Dec 7, 2016

If it's on a lazy loaded module, it could be related to router bug

@spali
Copy link

spali commented Dec 14, 2016

not sure about the reason, but I worked around by moving my data module which is responsible for the state stuff to the root and loaded it directly in the app module instead of loading it in a my shared module.
I think @qdouble is not that wrong :)

@paishin
Copy link

paishin commented Jan 8, 2017

hey @spali, I have the same issue, init functions being called multiple times but I am already loading them in my app.module. Could you please share some more info on your solution?

@spali
Copy link

spali commented Jan 9, 2017

Try loading the store module just in the bootstrapping module. This worked for me.

@mxchange
Copy link

mxchange commented Feb 7, 2017

Probably related: angular/angular#12869

@karolmie1
Copy link

@paishin If you are using lazy modules thats definitely it. Either get rid of them, or downgrade, as describd in angular/angular#12869. Init event fires twice by design. If it fires 4 times or more, then you have a problem.

@brandonroberts
Copy link
Member

The init event shouldn't fire twice even under normal circumstances. You should only provide store in your root AppModule's imports. If you're seeing it twice than that's a separate issue

@ilya-loskutov
Copy link

Hi,
same issue. Have you resolved it?

@mxchange
Copy link

This should be resolved in the latest angular4, or use older router angular/angular#12869

@robwormald
Copy link
Contributor

Please check this against NgRx v4, and if it’s still an issue, please reopen on https://github.com/ngrx/platform. Thanks!

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

No branches or pull requests