Skip to content

Commit

Permalink
Check whether packager is running in RCTBundleURLProvider for saved J…
Browse files Browse the repository at this point in the history
…SLocation

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
  • Loading branch information
jimmy623 authored and facebook-github-bot committed Jul 6, 2020
1 parent 8a14b98 commit 3d88249
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RNTester/RNTesterUnitTests/RCTBundleURLProviderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -94,6 +96,8 @@ - (void)testLocalhostURL

- (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];
Expand Down
5 changes: 5 additions & 0 deletions React/Base/RCTBundleURLProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ + (BOOL)isPackagerRunning:(NSString *)host
- (NSString *)packagerServerHost
{
NSString *location = [self jsLocation];
#if RCT_DEV_MENU
if (![RCTBundleURLProvider isPackagerRunning:location]) {
location = nil;
}
#endif
if (location != nil) {
return location;
}
Expand Down

0 comments on commit 3d88249

Please sign in to comment.