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

Store: Handling of @ngrx/store/update-reducers Action on Startup leads to strange behaviour for initialStates #906

Closed
tnobody opened this issue Mar 12, 2018 · 2 comments · Fixed by #1163

Comments

@tnobody
Copy link

tnobody commented Mar 12, 2018

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

What is the current behavior?

I configure a object as an initialState for the store. Unfortunately some values are "overridden" on start-up of the store/app.

Expected behavior:

All properties from the initial-state should remain untouched by any internal ngrx-action.

Minimal reproduction of the problem with instructions:

I think my explanation was i bit poor sofar (sorry it's hard to explain this). I think an example will show the problem:

https://stackblitz.com/edit/angular-6wbjq4

In this example everything is fine. The initial state is produced by the initState() function in app/app.state.ts.
screenshot 2018-03-12 18 02 05

BUT:

Remove the key 'featureB' from this init state will "break" this behaviour.

screenshot 2018-03-12 18 03 42

It seems to be caused by the combination function:

return function combination(state, action) {
state = state === undefined ? initialState : state;
let hasChanged = false;
const nextState: any = {};
for (let i = 0; i < finalReducerKeys.length; i++) {
const key = finalReducerKeys[i];
const reducer: any = finalReducers[key];
const previousStateForKey = state[key];
const nextStateForKey = reducer(previousStateForKey, action);
nextState[key] = nextStateForKey;
hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
}
return hasChanged ? nextState : state;
};
}

The function expects all possible state properties to be setted. If a property is not (in initialState) set the 'hasChanged' turns true and returns the nextState. This is some kind of an intermediated state (at least while the ' @ngrx/store/update-reducers'-Action is fired).

Version of affected browser(s),operating system(s), npm, node and ngrx:

@ngrx/store v 5.1 + 5.2

Other information:

This is not directly linked to the problem but another finding that confused me.
After '@ngrx/store/update-reducers' is fired all reducers are applied, even if they were already applied previously:

screenshot 2018-03-12 18 09 37

@russelporosky
Copy link

+1 We're seeing the repetition issue here as well on feature stores. The first feature will repeat 3 times, the second one repeats 4 times. Weird. In our case it's not causing any problems.

@johannesjo
Copy link

I'm experiencing the same thing with v6.1.0.

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

Successfully merging a pull request may close this issue.

4 participants