andreypopp / autobind-decorator

Decorator to automatically bind methods to class instances

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@autobind race-condition

fab1an opened this issue · comments

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?

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?

@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 ;).

Do you have any sample code?

@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.

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

Could you see my comment #57 (comment)?

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)