Skip to content

Commit 3d88249

Browse files
jimmy623facebook-github-bot
authored andcommitted
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
1 parent 8a14b98 commit 3d88249

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

RNTester/RNTesterUnitTests/RCTBundleURLProviderTests.m

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#import <React/RCTBundleURLProvider.h>
1111
#import <React/RCTUtils.h>
1212

13+
#import "OCMock/OCMock.h"
14+
1315
static NSString *const testFile = @"test.jsbundle";
1416
static NSString *const mainBundle = @"main.jsbundle";
1517

@@ -94,6 +96,8 @@ - (void)testLocalhostURL
9496

9597
- (void)testIPURL
9698
{
99+
id classMock = OCMClassMock([RCTBundleURLProvider class]);
100+
[[[classMock stub] andReturnValue:@YES] isPackagerRunning:[OCMArg any]];
97101
RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings];
98102
settings.jsLocation = @"192.168.1.1";
99103
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];

React/Base/RCTBundleURLProvider.mm

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ + (BOOL)isPackagerRunning:(NSString *)host
125125
- (NSString *)packagerServerHost
126126
{
127127
NSString *location = [self jsLocation];
128+
#if RCT_DEV_MENU
129+
if (![RCTBundleURLProvider isPackagerRunning:location]) {
130+
location = nil;
131+
}
132+
#endif
128133
if (location != nil) {
129134
return location;
130135
}

0 commit comments

Comments
 (0)