mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 01:40:08 +00:00
Moved constants export to bridge init
Summary: public Lazy export of module constants required a sync dispatch to the main thread, which was deadlocking in some of our projects. This moves the constants export to the initial bridge init, which may slightly increase initial startup time, but avoids the deadlock. Reviewed By: javache Differential Revision: D2911295 fb-gh-sync-id: 0d14a629ac4fc7ee21acd293c09595c18232659b shipit-source-id: 0d14a629ac4fc7ee21acd293c09595c18232659b
This commit is contained in:
parent
7b2b0c3c1c
commit
855d411321
@ -282,10 +282,11 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
|
||||
id module = preregisteredModules[moduleName];
|
||||
if (!module) {
|
||||
// Check if the module class, or any of its superclasses override init
|
||||
// or setBridge:. If they do, we assume that they are expecting to be
|
||||
// initialized when the bridge first loads.
|
||||
// or setBridge:, or has exported constants. If they do, we assume that
|
||||
// they are expecting to be initialized when the bridge first loads.
|
||||
if ([moduleClass instanceMethodForSelector:@selector(init)] != objectInitMethod ||
|
||||
[moduleClass instancesRespondToSelector:setBridgeSelector]) {
|
||||
[moduleClass instancesRespondToSelector:setBridgeSelector] ||
|
||||
RCTClassOverridesInstanceMethod(moduleClass, @selector(constantsToExport))) {
|
||||
module = [moduleClass new];
|
||||
if (!module) {
|
||||
module = (id)kCFNull;
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
@implementation RCTModuleData
|
||||
{
|
||||
NSDictionary<NSString *, id> *_constantsToExport;
|
||||
NSString *_queueName;
|
||||
__weak RCTBridge *_bridge;
|
||||
NSLock *_instanceLock;
|
||||
@ -79,6 +80,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTDidInitializeModuleNotification
|
||||
object:_bridge
|
||||
userInfo:@{@"module": _instance}];
|
||||
|
||||
if (RCTClassOverridesInstanceMethod(_moduleClass, @selector(constantsToExport))) {
|
||||
RCTAssertMainThread();
|
||||
_constantsToExport = [_instance constantsToExport];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,13 +187,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
|
||||
|
||||
- (NSArray *)config
|
||||
{
|
||||
__block NSDictionary<NSString *, id> *constants;
|
||||
if (RCTClassOverridesInstanceMethod(_moduleClass, @selector(constantsToExport))) {
|
||||
[self instance];
|
||||
RCTExecuteOnMainThread(^{
|
||||
constants = [_instance constantsToExport];
|
||||
}, YES);
|
||||
}
|
||||
__block NSDictionary<NSString *, id> *constants = _constantsToExport;
|
||||
_constantsToExport = nil; // Not needed any more
|
||||
|
||||
if (constants.count == 0 && self.methods.count == 0) {
|
||||
return (id)kCFNull; // Nothing to export
|
||||
|
Loading…
x
Reference in New Issue
Block a user