mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Gate TurboModule eager initialization
Summary: TurboModule eager initialization is a bit dangerous if we get it wrong, which we did (twice): T69449176. This diff gates TurboModule eager init behind a MC, so that we can control (i.e: turn off/on, and do gradually rollout of) TurobModule eager initialization in isolation from the larger TurboModules experiment. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D22460359 fbshipit-source-id: 3b8dce0529f1739bd68b8b16d6a28aa572d82c2c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
caf010914c
commit
e549f6984e
@@ -158,6 +158,10 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
|
||||
RCT_EXTERN BOOL RCTTurboModuleEnabled(void);
|
||||
RCT_EXTERN void RCTEnableTurboModule(BOOL enabled);
|
||||
|
||||
// Turn on TurboModule eager initialization
|
||||
RCT_EXTERN BOOL RCTTurboModuleEagerInitEnabled(void);
|
||||
RCT_EXTERN void RCTEnableTurboModuleEagerInit(BOOL enabled);
|
||||
|
||||
/**
|
||||
* Async batched bridge used to communicate with the JavaScript application.
|
||||
*/
|
||||
|
||||
@@ -115,6 +115,17 @@ void RCTEnableTurboModule(BOOL enabled)
|
||||
turboModuleEnabled = enabled;
|
||||
}
|
||||
|
||||
static BOOL turboModuleEagerInitEnabled = NO;
|
||||
BOOL RCTTurboModuleEagerInitEnabled(void)
|
||||
{
|
||||
return turboModuleEagerInitEnabled;
|
||||
}
|
||||
|
||||
void RCTEnableTurboModuleEagerInit(BOOL enabled)
|
||||
{
|
||||
turboModuleEagerInitEnabled = enabled;
|
||||
}
|
||||
|
||||
@interface RCTBridge () <RCTReloadListener>
|
||||
@end
|
||||
|
||||
|
||||
@@ -385,7 +385,7 @@ struct RCTInstanceCallback : public InstanceCallback {
|
||||
* id<RCTCxxBridgeDelegate> jsExecutorFactory may create and assign an id<RCTTurboModuleRegistry> object to
|
||||
* RCTCxxBridge If id<RCTTurboModuleRegistry> is assigned by this time, eagerly initialize all TurboModules
|
||||
*/
|
||||
if (_turboModuleRegistry) {
|
||||
if (_turboModuleRegistry && RCTTurboModuleEagerInitEnabled()) {
|
||||
for (NSString *moduleName in [_turboModuleRegistry eagerInitModuleNames]) {
|
||||
[_turboModuleRegistry moduleForName:[moduleName UTF8String]];
|
||||
}
|
||||
|
||||
@@ -396,7 +396,12 @@ static Class getFallbackClassFromName(const char *name)
|
||||
};
|
||||
|
||||
if ([self _requiresMainQueueSetup:moduleClass]) {
|
||||
if (!RCTIsMainQueue()) {
|
||||
/**
|
||||
* When TurboModule eager initialization is disabled, we expect TurboModules requiring main queue setup to be
|
||||
* required on background threads.
|
||||
* TODO(T69449176) Roll out TurboModule eager initialization, and remove this check.
|
||||
*/
|
||||
if (!RCTIsMainQueue() && !RCTTurboModuleEagerInitEnabled()) {
|
||||
RCTLogWarn(
|
||||
@"TurboModule \"%@\" requires synchronous dispatch onto the main queue to be initialized. This may lead to deadlock.",
|
||||
moduleClass);
|
||||
|
||||
Reference in New Issue
Block a user