diff --git a/React/Base/RCTModuleData.h b/React/Base/RCTModuleData.h index 398c0a2b9f8d44..04d6271eeedd5b 100644 --- a/React/Base/RCTModuleData.h +++ b/React/Base/RCTModuleData.h @@ -8,6 +8,7 @@ #import #import +#import "RCTDefines.h" @protocol RCTBridgeMethod; @protocol RCTBridgeModule; @@ -94,3 +95,6 @@ typedef id (^RCTBridgeModuleProvider)(void); @property (nonatomic, assign, readonly) BOOL implementsPartialBatchDidFlush; @end + +RCT_EXTERN void RCTSetIsMainQueueExecutionOfConstantsToExportDisabled(BOOL val); +RCT_EXTERN BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled(); diff --git a/React/Base/RCTModuleData.mm b/React/Base/RCTModuleData.mm index 14251ee6d590e6..c9c2ac79490ec9 100644 --- a/React/Base/RCTModuleData.mm +++ b/React/Base/RCTModuleData.mm @@ -29,6 +29,17 @@ int32_t getUniqueId() return counter++; } } +static BOOL isMainQueueExecutionOfConstantToExportDisabled = NO; + +void RCTSetIsMainQueueExecutionOfConstantsToExportDisabled(BOOL val) +{ + isMainQueueExecutionOfConstantToExportDisabled = val; +} + +BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled() +{ + return isMainQueueExecutionOfConstantToExportDisabled; +} @implementation RCTModuleData { NSDictionary *_constantsToExport; @@ -389,7 +400,8 @@ - (void)gatherConstants * require. */ BridgeNativeModulePerfLogger::moduleJSRequireEndingStart([moduleName UTF8String]); - if (_requiresMainQueueSetup) { + + if (!RCTIsMainQueueExecutionOfConstantsToExportDisabled() && _requiresMainQueueSetup) { if (!RCTIsMainQueue()) { RCTLogWarn(@"Required dispatch_sync to load constants for %@. This may lead to deadlocks", _moduleClass); } @@ -400,6 +412,7 @@ - (void)gatherConstants } else { _constantsToExport = [_instance constantsToExport] ?: @{}; } + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @""); } else { /** diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index a8e2ae2a9a3a10..7b2fc3808bce16 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -907,7 +907,9 @@ - (void)_prepareModulesWithDispatchGroup:(dispatch_group_t)dispatchGroup if (self.valid && ![moduleData.moduleClass isSubclassOfClass:[RCTCxxModule class]]) { [self->_performanceLogger appendStartForTag:RCTPLNativeModuleMainThread]; (void)[moduleData instance]; - [moduleData gatherConstants]; + if (!RCTIsMainQueueExecutionOfConstantsToExportDisabled()) { + [moduleData gatherConstants]; + } [self->_performanceLogger appendStopForTag:RCTPLNativeModuleMainThread]; } };