Check whether packager is running in RCTBundleURLProvider for saved JSLocation

Summary:
Changelog:
Adding packager running check when RCTBundleURLProvider is returning JSLocation, this prevents an invalid address from being returned which might cause various issues.

Reviewed By: cpojer

Differential Revision: D22390156

fbshipit-source-id: a20dbf63103158a34cbf6dc0ae8349b2f9e5b0a8
This commit is contained in:
Jimmy Zhang 2020-07-06 09:06:39 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 8a14b98193
Коммит 3d882495d5
2 изменённых файлов: 9 добавлений и 0 удалений

Просмотреть файл

@ -10,6 +10,8 @@
#import <React/RCTBundleURLProvider.h>
#import <React/RCTUtils.h>
#import "OCMock/OCMock.h"
static NSString *const testFile = @"test.jsbundle";
static NSString *const mainBundle = @"main.jsbundle";
@ -94,6 +96,8 @@ static NSURL *ipBundleURL()
- (void)testIPURL
{
id classMock = OCMClassMock([RCTBundleURLProvider class]);
[[[classMock stub] andReturnValue:@YES] isPackagerRunning:[OCMArg any]];
RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings];
settings.jsLocation = @"192.168.1.1";
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];

Просмотреть файл

@ -125,6 +125,11 @@ static NSURL *serverRootWithHostPort(NSString *hostPort)
- (NSString *)packagerServerHost
{
NSString *location = [self jsLocation];
#if RCT_DEV_MENU
if (![RCTBundleURLProvider isPackagerRunning:location]) {
location = nil;
}
#endif
if (location != nil) {
return location;
}