Skip to content

Commit

Permalink
fix: remove loadSourceForBridge in RCTRootViewFactory (facebook#43656)
Browse files Browse the repository at this point in the history
Summary:
This PR removes forward declaration of `loadSourceForBridge` methods from the RCTRootViewFactory as it was causing an issue on old architecture, where the RedBox wouldn't popup when metro wasn't running.

As stated by Kudo [here](reactwg/react-native-releases#177):

> the problem was coming from the implementation
> https://github.com/facebook/react-native/blob/00725fadff28bb3c7fed65f208e647f0dab69e75/packages/react-native/React/CxxBridge/RCTCxxBridge.mm#L519-L540
>
> we should dynamically override loadSourceForBridge:onProgress:onComplete: and loadSourceForBridge:withBlock: in RCTRootViewFactory only when AppDelegate override it. one way to achieve this might be tricky that we may need to override respondsToSelector:.
>
> otherwise, we could just skip the loadSourceForBridge:onProgress:onComplete: and loadSourceForBridge:withBlock: support.

There is no straight forward solution to implement this without some _hacks_ so I'm removing this forward block for now.

## Changelog:

[IOS] [FIXED] - remove loadSourceForBridge in RCTRootViewFactory

Pull Request resolved: facebook#43656

Test Plan: CI Green

Reviewed By: rshest

Differential Revision: D55485094

Pulled By: cortinico

fbshipit-source-id: 1e391e0795c3d99686f2805165f64a7715b013f6
  • Loading branch information
okwasniewski authored and facebook-github-bot committed Apr 2, 2024
1 parent c32a053 commit 0c02b26
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 50 deletions.
16 changes: 0 additions & 16 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,6 @@ - (RCTRootViewFactory *)createRCTRootViewFactory
};
}

if ([self respondsToSelector:@selector(loadSourceForBridge:withBlock:)]) {
configuration.loadSourceForBridgeBlock =
^void(RCTBridge *_Nonnull bridge, RCTSourceLoadBlock _Nonnull loadCallback) {
[weakSelf loadSourceForBridge:bridge withBlock:loadCallback];
};
}

if ([self respondsToSelector:@selector(loadSourceForBridge:onProgress:onComplete:)]) {
configuration.loadSourceForBridgeProgressBlock =
^(RCTBridge *_Nonnull bridge,
RCTSourceLoadProgressBlock _Nonnull onProgress,
RCTSourceLoadBlock _Nonnull loadCallback) {
[weakSelf loadSourceForBridge:bridge onProgress:onProgress onComplete:loadCallback];
};
}

return [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:self];
}

Expand Down
21 changes: 3 additions & 18 deletions packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ typedef NSURL *_Nullable (^RCTSourceURLForBridgeBlock)(RCTBridge *bridge);
typedef NSArray<id<RCTBridgeModule>> *_Nonnull (^RCTExtraModulesForBridgeBlock)(RCTBridge *bridge);
typedef NSDictionary<NSString *, Class> *_Nonnull (^RCTExtraLazyModuleClassesForBridge)(RCTBridge *bridge);
typedef BOOL (^RCTBridgeDidNotFindModuleBlock)(RCTBridge *bridge, NSString *moduleName);
typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBlock loadCallback);
typedef void (^RCTLoadSourceForBridgeProgressBlock)(
RCTBridge *bridge,
RCTSourceLoadProgressBlock onProgress,
RCTSourceLoadBlock loadCallback);

#pragma mark - RCTRootViewFactory Configuration
@interface RCTRootViewFactoryConfiguration : NSObject
Expand Down Expand Up @@ -89,6 +84,9 @@ typedef void (^RCTLoadSourceForBridgeProgressBlock)(
* @returns: a newly created instance of RCTBridge.
*/
@property (nonatomic, nullable) RCTCreateBridgeWithDelegateBlock createBridgeWithDelegate;

#pragma mark - RCTBridgeDelegate blocks

/**
* Block that returns the location of the JavaScript source file. When running from the packager
* this should be an absolute URL, e.g. `http://localhost:8081/index.ios.bundle`.
Expand Down Expand Up @@ -127,19 +125,6 @@ typedef void (^RCTLoadSourceForBridgeProgressBlock)(
*/
@property (nonatomic, nullable) RCTBridgeDidNotFindModuleBlock bridgeDidNotFindModule;

/**
* The bridge will automatically attempt to load the JS source code from the
* location specified by the `sourceURLForBridge:` method, however, if you want
* to handle loading the JS yourself, you can do so by implementing this method.
*/
@property (nonatomic, nullable) RCTLoadSourceForBridgeProgressBlock loadSourceForBridgeProgressBlock;

/**
* Similar to loadSourceForBridge:onProgress:onComplete: but without progress
* reporting.
*/
@property (nonatomic, nullable) RCTLoadSourceForBridgeBlock loadSourceForBridgeBlock;

@end

#pragma mark - RCTRootViewFactory
Expand Down
16 changes: 0 additions & 16 deletions packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,6 @@ - (BOOL)bridge:(RCTBridge *)bridge didNotFindModule:(NSString *)moduleName
return NO;
}

- (void)loadSourceForBridge:(RCTBridge *)bridge withBlock:(RCTSourceLoadBlock)loadCallback
{
if (_configuration.loadSourceForBridgeBlock != nil) {
_configuration.loadSourceForBridgeBlock(bridge, loadCallback);
}
}

- (void)loadSourceForBridge:(RCTBridge *)bridge
onProgress:(RCTSourceLoadProgressBlock)onProgress
onComplete:(RCTSourceLoadBlock)loadCallback
{
if (_configuration.loadSourceForBridgeProgressBlock != nil) {
_configuration.loadSourceForBridgeProgressBlock(bridge, onProgress, loadCallback);
}
}

- (NSURL *)bundleURL
{
return self->_configuration.bundleURL;
Expand Down

0 comments on commit 0c02b26

Please sign in to comment.