Lucifier129 / react-lite

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

this.refs sometimes equals to null #22

Closed fritx closed 8 years ago

fritx commented 8 years ago
  render() {
    return (
      <img className="avatar-one" ref="img"
        onLoad={()=>{
          console.log('onload this.refs', this.refs)
        }}
        onError={()=>{
          console.log('onerror this.refs', this.refs)
        }} />
    )
  }

Hey @Lucifier129 In react-lite, I found that this.refs sometimes equals to null, called in onLoad/onError of <img> tag. The probability is very small, but I can always reproduce it by very frequent rendering. It causes a bug in my app. And when I try the regular React, it's fine.

Lucifier129 commented 8 years ago

I got the problem and try to fixed it in version 0.0.16.

Even the element has been removed, onload/onerror would still be triggered. react-lite will removeEvent all the event handler in its props at v0.0.16.

please update react-lite, and try again.

Lucifier129 commented 8 years ago

sorry about misunderstand your description.

I had try many time about onload/onerror, and can't reappear this.refs == null.

I wonder which browser did you use. (since I tryed it at chrome), maybe other browser's onload/onerror event would be triggered, even the element did'nt insert to document but already in memory.

You can add debugger when onload event is calling, and check whether the img elment was inserted to document or not.

fritx commented 8 years ago

But it seems that the problem was gone after upgrading react-lite last week.

Lucifier129 commented 8 years ago

OK:-)

Now which version of react-lite are you using?