Lucifier129 / react-lite

An implementation of React v15.x that optimizes for small script size
MIT License
1.73k stars 98 forks source link

Cannot read property '$updater' of undefined #82

Closed tysonnero closed 7 years ago

tysonnero commented 8 years ago

Uncaught TypeError: Cannot read property '$updater' of undefined

When I include the below in my webpack.config to use react-lite in place of react, I rec'ing the above error. When I remove react-lite, my app works as expected.

Is there any good way of debugging this?

resolve: {
    alias: {
      'react': 'react-lite',
      'react-dom': 'react-lite'
    }
  }
tysonnero commented 8 years ago
screen shot 2016-11-06 at 2 27 54 pm

The uid it's looking for (57) does not exist in node.cache. There uid's that are in cache are 62 and 66. One is the component which should be being loaded and the other is Connect.

tysonnero commented 8 years ago

As I dug in a little more, I found that this is happening after dispatching a redux action from the componentWillReceiveProps of the component. Not really sure what else to look for.

tysonnero commented 8 years ago

I move the dispatch out of componentWillReceiveProps to another area of the application, and the issue has gone away. Although fixed, I'm going to leave open to see if anyone can give me some insight into why this would have happened. Thanks!

roastlechon commented 7 years ago

I have this issue too

roastlechon commented 7 years ago

A quick glance at our code shows that none of our code is dispatching a redux action in the componentWillReceiveProps lifecycle directly or indirectly.

beholderrk commented 7 years ago

I suppose the problem here https://github.com/Lucifier129/react-lite/commit/14c164b73490f3d9b576c6b9c3af32c434a45893#diff-33385622f0cbc5bbb7cd88879f6a81acR269

If component have componentWillReceiveProps (like react-redux connect component) then updateVcomponent function crash updater.isPending flag. Even if updater.isPending is true always will be set to false after this code

    if (component.componentWillReceiveProps) {
        updater.isPending = true
        component.componentWillReceiveProps(nextProps, componentContext)
        updater.isPending = false
    }

As result updateVcomponent may executed many many times when it should't. When I remove updater.isPending = true updater.isPending = false it solve this issue.

Why it's necessary to toggle the flag if a component has componentWillReceiveProps?

Lucifier129 commented 7 years ago

@beholderrk when updater.isPending === true, component.setState will not cause rendering directly, and setState in life-cycle method componentWillReceiveProps should not cause rendering

beholderrk commented 7 years ago

pr #88

Lucifier129 commented 7 years ago

@beholderrk Thanks PR, it can be merged safely, and v0.15.29 now has been released;)