Skip to content

Move safety checks inside combineReducer to first invocation #717

Closed
@gaearon

Description

@gaearon

Currently we make a bunch of invariant tests inside combineReducers() to make sure it's not being misused in common ways. These tests currently occur at the combineReducers() call time.

This makes Redux DevTools unable to catch the errors inside reducers, as they often trigger those invariants to blow up during module definition, and abort hot reloading. Instead, I propose to move the tests to the first real invocation of the combined reducer. In most cases that would be createStore call because it causes an implicit initial dispatch. This way Redux DevTools can catch and display such errors.

Shall we do that? The code would change to be like

  var reducerSanityVerified;
  var stateShapeVerified;

  // don't do it here

  return function combination(state = defaultState, action) {
    if (!reducerSanityVerified) {
      Object.keys(finalReducers).forEach(key => {
        // do that stuff

screen shot 2015-09-13 at 07 09 31

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions