Skip to content

Commit

Permalink
fix(react-native-host): enable concurrentRoot when Fabric is (#2961)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Feb 12, 2024
1 parent 36176a5 commit e02e503
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .changeset/nine-rules-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@rnx-kit/react-native-host": patch
---

Enable `concurrentRoot` by default when New Architecture is enabled.

Having `concurrentRoot` disabled when Fabric is enabled is not
recommended:
https://github.com/facebook/react-native/commit/7eaabfb174b14a30c30c7017195e8110348e5f44

As of 0.74, it won't be possible to opt-out:
https://github.com/facebook/react-native/commit/30d186c3683228d4fb7a42f804eb2fdfa7c8ac03
4 changes: 2 additions & 2 deletions packages/react-native-host/cocoa/RNXTurboModuleAdapter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ @implementation RNXTurboModuleAdapter {

// MARK: - RCTTurboModuleManagerDelegate details

- (Class)getModuleClassFromName:(const char *)name
- (Class)getModuleClassFromName:(char const *)name
{
return RCTCoreModulesClassProvider(name);
}

- (std::shared_ptr<facebook::react::TurboModule>)
getTurboModule:(const std::string &)name
getTurboModule:(std::string const &)name
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
{
return nullptr;
Expand Down
17 changes: 15 additions & 2 deletions packages/react-native-host/cocoa/ReactNativeHost+View.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import <React/RCTFabricSurface.h>
#import <React/RCTSurfaceHostingProxyRootView.h>
#endif // __has_include(<React/RCTFabricSurfaceHostingProxyRootView.h>)
static NSString *const kReactConcurrentRoot = @"concurrentRoot";
#else
#import <React/RCTRootView.h>
#endif // USE_FABRIC
Expand Down Expand Up @@ -36,15 +37,27 @@ - (RNXView *)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties;
{
#ifdef USE_FABRIC
// Having `concurrentRoot` disabled when Fabric is enabled is not recommended:
// https://github.com/facebook/react-native/commit/7eaabfb174b14a30c30c7017195e8110348e5f44
// As of 0.74, it won't be possible to opt-out:
// https://github.com/facebook/react-native/commit/30d186c3683228d4fb7a42f804eb2fdfa7c8ac03
NSMutableDictionary *initialProps =
initialProperties == nil
? [NSMutableDictionary dictionaryWithObjectsAndKeys:@YES, kReactConcurrentRoot, nil]
: [initialProperties mutableCopy];
if (initialProps[kReactConcurrentRoot] == nil) {
initialProps[kReactConcurrentRoot] = @YES;
}

#if __has_include(<React/RCTFabricSurfaceHostingProxyRootView.h>)
return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:self.bridge
moduleName:moduleName
initialProperties:initialProperties];
initialProperties:initialProps];
#else
RCTFabricSurface *surface =
[[RCTFabricSurface alloc] initWithSurfacePresenter:self.surfacePresenter
moduleName:moduleName
initialProperties:initialProperties];
initialProperties:initialProps];
return [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];
#endif // __has_include(<React/RCTFabricSurfaceHostingProxyRootView.h>)
#else
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-host/cocoa/ReactNativeHost.mm
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ - (void)shutdown

- (void)usingModule:(Class)moduleClass block:(void (^)(id<RCTBridgeModule> _Nullable))block
{
const BOOL requiresMainQueueSetup =
BOOL const requiresMainQueueSetup =
[moduleClass respondsToSelector:@selector(requiresMainQueueSetup)] &&
[moduleClass requiresMainQueueSetup];
if (requiresMainQueueSetup && !RCTIsMainQueue()) {
Expand Down

0 comments on commit e02e503

Please sign in to comment.