Skip to content

Commit

Permalink
remove fallbackResource from RCTBundleURLProvider api
Browse files Browse the repository at this point in the history
Summary:
if you xgbs for `fallbackResource:`, you'll find only one place is actually passing a non-nil value to this parameter.

https://www.internalfb.com/code/fbsource/fbobjc/Apps/Wilde/FBReactModule2/FBReactModuleAPI/FBReactModuleAPI/FBReactSourceLoaderProd.mm?lines=79

but if we look at the implementation, `@"main"` is the fallback value...

https://www.internalfb.com/code/fbsource/[cd930f5f15cca0feb732317147de318ce6aa1db3]/xplat/js/react-native-github/React/Base/RCTBundleURLProvider.mm?lines=224

let's just simplify this api and get rid of this parameter.

Changelog: [Internal]

Reviewed By: raedle

Differential Revision: D32641476

fbshipit-source-id: 637a8c0f7bea834bfecd804a521155f41aaaff7e
  • Loading branch information
philIip authored and facebook-github-bot committed Dec 16, 2021
1 parent 7dfb08a commit 0912ee1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
15 changes: 6 additions & 9 deletions React/Base/RCTBundleURLProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,22 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
* if resourceName or extension are nil, "main" and "jsbundle" will be
* used, respectively.
* if extension is nil, "jsbundle" will be used.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
fallbackResource:(NSString *)resourceName

This comment has been minimized.

Copy link
@therealgilles

therealgilles Apr 19, 2022

@philIip: What's the right way to specify a different bundle name now that fallbackResource is gone, like in react-native-threads on this line?

fallbackExtension:(NSString *)extension;
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackExtension:(NSString *)extension;

/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSString *)resourceName;
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot;

/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle. If resourceName or extension
* are nil, "main" and "jsbundle" will be used, respectively.
* the fallback offline JS bundle. If extension is nil,
* "jsbundle" will be used.
*/
- (NSURL *)jsBundleURLForFallbackResource:(NSString *)resourceName fallbackExtension:(NSString *)extension;
- (NSURL *)jsBundleURLForFallbackExtension:(NSString *)extension;

/**
* Returns the resourceURL for a given bundle entrypoint and
Expand Down
15 changes: 6 additions & 9 deletions React/Base/RCTBundleURLProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,23 @@ - (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot
runModule:NO];
}

- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
fallbackResource:(NSString *)resourceName
fallbackExtension:(NSString *)extension
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackExtension:(NSString *)extension
{
return [self jsBundleURLForBundleRoot:bundleRoot
fallbackURLProvider:^NSURL * {
return [self jsBundleURLForFallbackResource:resourceName fallbackExtension:extension];
return [self jsBundleURLForFallbackExtension:extension];
}];
}

- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSString *)resourceName
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
{
return [self jsBundleURLForBundleRoot:bundleRoot fallbackResource:resourceName fallbackExtension:nil];
return [self jsBundleURLForBundleRoot:bundleRoot fallbackExtension:nil];
}

- (NSURL *)jsBundleURLForFallbackResource:(NSString *)resourceName fallbackExtension:(NSString *)extension
- (NSURL *)jsBundleURLForFallbackExtension:(NSString *)extension
{
resourceName = resourceName ?: @"main";
extension = extension ?: @"jsbundle";
return [[NSBundle mainBundle] URLForResource:resourceName withExtension:extension];
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:extension];
}

- (NSURL *)resourceURLForResourceRoot:(NSString *)root
Expand Down
6 changes: 2 additions & 4 deletions React/CoreModules/RCTDevMenu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ - (void)addItem:(RCTDevMenuItem *)item
- (void)setDefaultJSBundle
{
[[RCTBundleURLProvider sharedSettings] resetToDefaults];
self->_bundleManager.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForFallbackResource:nil
fallbackExtension:nil];
self->_bundleManager.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForFallbackExtension:nil];
RCTTriggerReloadCommandListeners(@"Dev menu - reset to default");
}

Expand Down Expand Up @@ -363,8 +362,7 @@ - (void)setDefaultJSBundle
[bundleManager resetBundleURL];
} else {
bundleManager.bundleURL = [[RCTBundleURLProvider sharedSettings]
jsBundleURLForBundleRoot:bundleRoot
fallbackResource:nil];
jsBundleURLForBundleRoot:bundleRoot];
}

RCTTriggerReloadCommandListeners(@"Dev menu - apply changes");
Expand Down
3 changes: 1 addition & 2 deletions packages/rn-tester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ - (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWith

- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
{
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"packages/rn-tester/js/RNTesterApp.ios"
fallbackResource:nil];
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"packages/rn-tester/js/RNTesterApp.ios"];
}

- (void)initializeFlipper:(UIApplication *)application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ - (void)testBundleURL
{
RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings];
settings.jsLocation = nil;
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile];
if (!getenv("CI_USE_PACKAGER")) {
XCTAssertEqualObjects(URL, mainBundleURL());
} else {
Expand All @@ -112,7 +112,7 @@ - (void)testLocalhostURL
[[[classMock stub] andReturnValue:@YES] isPackagerRunning:[OCMArg any] scheme:[OCMArg any]];
RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings];
settings.jsLocation = @"localhost";
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile];
XCTAssertEqualObjects(URL, localhostBundleURL());
}

Expand All @@ -122,7 +122,7 @@ - (void)testIPURL
[[[classMock stub] andReturnValue:@YES] isPackagerRunning:[OCMArg any] scheme:[OCMArg any]];
RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings];
settings.jsLocation = @"192.168.1.1";
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile];
XCTAssertEqualObjects(URL, ipBundleURL());
}

Expand Down

0 comments on commit 0912ee1

Please sign in to comment.