Repository: reduxjs/redux

Issue #3488: State doesn't update when replaceReducers is called with combineReducers and one of the reducers passed to it is removed. 
Created: 2019-07-31T11:24:02Z
Do you want to request a feature or report a bug?
bug
What is the current behavior?
The combineReducers function does't detect if one of the reducers passed to it is removed(via replaceReducers) and thus returns an old state.
// Reducers
const foo = (state = { value: 'foo' } ) => state
const bar = (state = { value: 'bar' }) => state

const ACTION = { type: 'ACTION' };

const originalCompositeReducer = combineReducers({ foo, bar })
const store = createStore(originalCompositeReducer)
store.dispatch(ACTION)


const initialState = store.getState() // returns -> { 
 //                                                   foo: { value: 'foo' }, 
 //                                                   bar: { value: 'bar' } 
 //                                                }

// now remove `foo` reducer
store.replaceReducer(combineReducers({ bar }))
const nextState = store.getState() // returns -> { 
//                                                 foo: { value: 'foo' }, 
//                                                 bar: { value: 'bar' } 
//                                                }
//                      should have returned -> { bar: { value: 'bar' } }
expect(nextState).not.toBe(initialState) // --> this fails
Steps to reproduce:
Open JSFiddle Link:

Click "Dispatch action" button
-> 2 boxes gets rendered,  one of foo and other of bar.
Click "Replace Reducer: remove bar reducer" button
-> Again, 2 boxes gets rendered,  one of foo and other of bar.
Expected: Only one box should render, i.e. box of bar only.

What is the expected behavior?
The combineReducers function should detect if one or more reducers passed to it is removed(via replaceReducers) and thus should update the store with new state.
Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
Redux Version: V4.0.4
OS: MAC
Worked on previous versions: no.

Duplicate issue #3643: dynamic reducers can not work with combineReducers
Created: 2019-11-30T12:27:15Z
Do you want to request a feature or report a bug?
bug
Bug Reports
i have an app, whats reducer is dynamic. the reducer is combined by combineReducers,but combineReducers seems have a cache Strategy, if new reducer map have the same result in old state, after traversal, it will return old state.even if the new reducer map has less reducer key than old reducer map, in this case i want to get exact next state after i invoke replaceReducer.🙂
What is the current behavior?
combineReducers return old state in the case next reducer map has less key than previous reducer map.
Steps to Reproduce
👉 https://codesandbox.io/s/interesting-chandrasekhar-h56kh?fontsize=14&hidenavigation=1&theme=dark 👈
What is the expected behavior?
combineReducers return next state in the case: next reducer map has less key than previous reducer map.
Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
redux 4.0.4
What docs changes are needed to explain this?
if combineReducers could not work with replaceReducer in this case, i wish could got a office notice😁

Closing comment (2019-11-30T21:28:08Z): Duplicate of #3488 and was fixed in #3490, but we haven't released it yet.