Skip to content
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

[iOS] RNTester enable concurrent root when using Fabric #41166

Closed

Conversation

zhongwuzw
Copy link
Contributor

Summary:

RNTester's AppDelegate override prepareInitialProps method of super class RCTAppDelegate

initProps[kRNConcurrentRoot] = @([self fabricEnabled]);
, so we missed concurrentRoot initial prop.

image

cc @javache @cipolleschi

Changelog:

[IOS] [FIXED] - RNTester enable concurrent root when using Fabric

Test Plan:

Warning disappear.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Oct 24, 2023
@analysis-bot
Copy link

analysis-bot commented Oct 24, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 17,649,149 -2
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 21,026,731 -4,097
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 586de42
Branch: main

Copy link
Member

@javache javache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the docs, prepareInitialProps is a method that's supposed to be overwritten (although confusing that we have two ways do it - we also have the initialProps property...)

Maybe a better fix would be to change RCTAppDelegate.m to always override this property consistently, outside of prepareInitialProps.

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, very well spotted. Thank you for this fix!

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@zhongwuzw
Copy link
Contributor Author

@javache @cipolleschi Thanks for the review, should I need to update the commit like below?

diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
index 43d4b0bd4b0..fa409a1d8ce 100644
--- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
+++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
@@ -122,7 +122,12 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
     [self unstable_registerLegacyComponents];
     [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
 #endif
-    NSDictionary *initProps = [self prepareInitialProps];
+    NSMutableDictionary *initProps = [[self prepareInitialProps] mutableCopy] ?: [NSMutableDictionary new];
+#ifdef RCT_NEW_ARCH_ENABLED
+    // Hardcoding the Concurrent Root as it it not recommended to
+    // have the concurrentRoot turned off when Fabric is enabled.
+    initProps[kRNConcurrentRoot] = @([self fabricEnabled]);
+#endif
     rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
   }
   self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
@@ -144,15 +149,7 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
 
 - (NSDictionary *)prepareInitialProps
 {
-  NSMutableDictionary *initProps = self.initialProps ? [self.initialProps mutableCopy] : [NSMutableDictionary new];
-
-#ifdef RCT_NEW_ARCH_ENABLED
-  // Hardcoding the Concurrent Root as it it not recommended to
-  // have the concurrentRoot turned off when Fabric is enabled.
-  initProps[kRNConcurrentRoot] = @([self fabricEnabled]);
-#endif
-
-  return initProps;
+  return self.initialProps;
 }
 
 - (RCTBridge *)createBridgeWithDelegate:(id<RCTBridgeDelegate>)delegate launchOptions:(NSDictionary *)launchOptions
diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm
index 3f1209e3615..40582e7296b 100644
--- a/packages/rn-tester/RNTester/AppDelegate.mm
+++ b/packages/rn-tester/RNTester/AppDelegate.mm
@@ -36,12 +36,12 @@ NSString *kBundlePath = @"js/RNTesterApp.ios";
   self.moduleName = @"RNTesterApp";
   // You can add your custom initial props in the dictionary below.
   // They will be passed down to the ViewController used by React Native.
-  self.initialProps = [self setUpInitialProps];
+  self.initialProps = [self prepareInitialProps];
 
   return [super application:application didFinishLaunchingWithOptions:launchOptions];
 }
 
-- (NSDictionary *)setUpInitialProps
+- (NSDictionary *)prepareInitialProps
 {
   NSMutableDictionary *initProps = [NSMutableDictionary new];
 

@cipolleschi
Copy link
Contributor

Oh sorry, I haven't seen the @javache review. @zhongwuzw I think that the best way would be in the RCTAppDelegate:

  1. create another method that set the concurrent root
  2. keep the prepareInitialProps as returning an empty dictionary, so it is safe to override
  3. merge the two dictionaries before using them around line 124

So, if in the future we have to add other prop to the initialProps that we have to handle internally, we already have a place where to put them.

Thoughts?

@zhongwuzw
Copy link
Contributor Author

@cipolleschi Done, please review again.

@zhongwuzw
Copy link
Contributor Author

@javache Done. please review again, thanks!

@zhongwuzw
Copy link
Contributor Author

zhongwuzw commented Oct 25, 2023

@javache Done. Also update commit to fix the bridgeless mode.

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@github-actions
Copy link

This pull request was successfully merged by @zhongwuzw in b1e92d6.

When will my fix make it into a release? | Upcoming Releases

@github-actions github-actions bot added the Merged This PR has been merged. label Oct 25, 2023
Othinn pushed a commit to Othinn/react-native that referenced this pull request Oct 30, 2023
Summary:
RNTester's `AppDelegate` override `prepareInitialProps` method of super class `RCTAppDelegate` https://github.com/facebook/react-native/blob/70acd3f7d9edae9e40cc4603bede9778da281a85/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm#L152, so we missed `concurrentRoot` initial prop.

![image](https://github.com/facebook/react-native/assets/5061845/12af5815-afe6-46f0-8107-54ca443b4962)

cc javache cipolleschi

## Changelog:

[IOS] [FIXED] - RNTester enable concurrent root when using Fabric

Pull Request resolved: facebook#41166

Test Plan: Warning disappear.

Reviewed By: cipolleschi

Differential Revision: D50596693

Pulled By: javache

fbshipit-source-id: d73a17cd137b3088405f86b739cb0ed7b5a9839e
blakef pushed a commit that referenced this pull request Jan 26, 2024
Summary:
RNTester's `AppDelegate` override `prepareInitialProps` method of super class `RCTAppDelegate` https://github.com/facebook/react-native/blob/70acd3f7d9edae9e40cc4603bede9778da281a85/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm#L152, so we missed `concurrentRoot` initial prop.

![image](https://github.com/facebook/react-native/assets/5061845/12af5815-afe6-46f0-8107-54ca443b4962)

cc javache cipolleschi

[IOS] [FIXED] - RNTester enable concurrent root when using Fabric

Pull Request resolved: #41166

Test Plan: Warning disappear.

Reviewed By: cipolleschi

Differential Revision: D50596693

Pulled By: javache

fbshipit-source-id: d73a17cd137b3088405f86b739cb0ed7b5a9839e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants