leoasis / redux-immutable-state-invariant

Redux middleware that detects mutations between and outside redux dispatches. For development use only.
MIT License
937 stars 37 forks source link

Slow when action contains a Event object #29

Closed jackielii closed 6 years ago

jackielii commented 7 years ago

The cause of the problem is at: https://github.com/leoasis/redux-immutable-state-invariant/blob/e885777567b5d82740b3f8dcf548b36bdcca9ce0/src/index.js#L54

The problem: In react there is this bit of code: onClick={this.props.goBack} When the user click on this button, it calls react-router-redux's goBack action

In React router redux middleware:

function goBack(...args) {
  return {
    ...
    payload: { method: 'goBack', args }
  }
}

The following happened:

  1. user click on the button
  2. goBack fired with arguments of ReactProxy, and ReactEvent
  3. react-router-redux returns an action with payload of the above arguments
  4. redux-immutable-state-invariant stringify the whole react proxy and event tree.

It takes over a minute for that stringify to finish

Arguably the component author should've written: onClick={() => this.props.goBack()} However this is not a good practice of having another level of function just to work around the problem

If I understand correctly, the stringify here is only for displaying an error message? I reckon it should not try so hard to strigify everything.

jackielii commented 6 years ago

Thanks! Looking forward to a release.

Regards,