Closed
Description
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 offoo
and other ofbar
. - Click "Replace Reducer: remove
bar
reducer" button
-> Again, 2 boxes gets rendered, one offoo
and other ofbar
.
Expected: Only one box should render, i.e. box ofbar
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.
Metadata
Metadata
Assignees
Labels
No labels