-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes races bug in react-native > 0.52 #938
Conversation
@@ -5,6 +5,7 @@ | |||
#import <FirebaseAnalytics/FIRAnalyticsConfiguration.h> | |||
|
|||
@implementation RNFirebaseAnalytics | |||
@synthesize methodQueue = _methodQueue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taxidermic I'm unsure why we need this queue, as the dispatch method is using dispatch_get_main_queue()
, not the methodQueue
you've defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The queue that will be used to call all exported methods. If omitted, this will call on a default background queue, which is avoids blocking the main thread.
....
If you don't want to specify the queue yourself, but you need to use it
inside your class (e.g. if you have internal methods that need to dispatch
onto that queue), you can just add `@synthesize methodQueue = _methodQueue;`
and the bridge will populate the methodQueue property for you automatically
when it initializes the module.
Docs I mentioned tells that if methodQueue
is not synthesized, methods marked with RCT_EXPORT_METHOD
will be called in global concurrent queue, which leads to messing. But! This passage lead me to wrong conclusions. My colleague(@vovkasm) made a big research about react-native/iOS interactions, and in fact it seems that react-native always makes that thing: https://github.com/facebook/react-native/blob/master/React/Base/RCTModuleData.mm#L209
So, it brings us to the point, where we don't need to use @synthesize methodQueue = _methodQueue;
. But I would like to test it at first, so I'll do it and answer you tomorrow about the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisbianca Tested, yes, it works without @synthesize methodQueue = _methodQueue;
!
Will you edit it by yourself, or should I send new pull_request? (I'm not sure how it works here ^^")
Btw, it fixes races only inside these structures separately. So, it's still possible, that
firebase.SetCurrentScreen(someProps)
firebase.LogEvent(anotherProps)
may mess up.
Though, several calls SetCurrentScreen
will save their order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean:
firebase.SetCurrentScreen(A)
firebase.LogEvent(E1)
firebase.SetCurrentScreen(B)
firebase.LogEvent(E2)
E1.screen == A и E2.screen == B, otherwords results will be accurate, though in Firebase Console you may see:
E1
screen_view(A)
screen_view(B)
E2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @taxidermic , this is a good step in the right direction. We'll consider how best to synchronize across all the methods.
In newer versions of react-native
dispatch_async
insetCurrentScreen
causes mixed order. It's obvious if you make several calls ofsetCurrentScreen
andlogEvent
in a small amount of time.See: https://github.com/facebook/react-native/blob/0.54-stable/React/Base/RCTBridgeModule.h#L112