andreypopp / autobind-decorator

Decorator to automatically bind methods to class instances
MIT License
1.45k stars 66 forks source link

@autobind race-condition #36

Closed fab1an closed 6 years ago

fab1an commented 8 years ago

Hi, I have a complex react-native app, where I get a race-condition sometimes when having multiple setState firing. In the error-case this appears not to be set, when the method is called.

I'm sorry to not be able to provide a test-case, but the issue disappears when I replace the @autobind method with an es7 class property.

What I'd like to know is how this is possible. Is it possible that react calls a method on the class before @autobind had the chance to adjust this?

stevemao commented 8 years ago

What I'd like to know is how this is possible. Is it possible that react calls a method on the class before @autobind had the chance to adjust this?

I think the point of this module is to change the context so that you don't have to worry about it.

@fab1an do you have to use this module? Can you use compose to achieve what you want?

fab1an commented 8 years ago

@stevemao I replaced the usage of autobind with myFun= () => {} class-properties, which seems to work.

I'd just like to know how such a race-condition is possible, since I like to understand my code ;).

stevemao commented 8 years ago

Do you have any sample code?

fab1an commented 8 years ago

@stevemao I have a hard time myself reproducing the error with my production code, because it only happens if certain events happen to fast after another.

The code consists of many nested components, async actions, which partly communicate over the react-native JS/Java Bridge and so on, so I'm afraid I can't show any code.

I don't know how this plugin works, but is it possible that while this is being bound, a render happens? It's possible that this is on a node that is unmounted, but like I said, hard to reproduce.

richardszalay commented 7 years ago

FWIW, I've replicated this in a RN app. If I can create a small reproducable code snippet, I'll post something.

stevemao commented 7 years ago

Could you see my comment https://github.com/andreypopp/autobind-decorator/pull/57#issuecomment-312410441?

Val0429 commented 6 years ago

For me it also happened on my complex project, and only with Android Project + Remote JS Debugging Off. On both emulator & real devices. With likely 20% occurrence rate.

(and note with babel-plugin-transform-decorators-legacy@1.3.4)