Skip to content

Commit f9df933

Browse files
reyalpsircfacebook-github-bot
authored andcommitted
Fixes iOS reload through metro "r" command key (#28477)
Summary: This allows the iOS device to be reloaded through the metro command line, besides the fact that whenever packagerServerHost is called, it will only get the IP address once when debugging. ## Changelog [iOS] [Fixed] - Fixed connection of metro reload command to iOS device Pull Request resolved: #28477 Test Plan: - Build any react-native project in debug mode to an iOS device connected through USB - Press the “r” key on the terminal that is running metro - The device should now reload the project Reviewed By: cpojer Differential Revision: D20818462 Pulled By: TheSavior fbshipit-source-id: 6d9792447d205223dad8fbd955518885427cbba8
1 parent 25836bc commit f9df933

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

React/Base/RCTBundleURLProvider.h

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ extern const NSUInteger kRCTBundleURLProviderDefaultPort;
3131
*/
3232
- (void)resetToDefaults;
3333

34+
/**
35+
* Return the server host. If its a development build and there's no jsLocation defined,
36+
* it will return the server host IP address
37+
*/
38+
- (NSString *)packagerServerHost;
39+
3440
#if RCT_DEV
3541
- (BOOL)isPackagerRunning:(NSString *)host;
3642
#endif

React/DevSupport/RCTPackagerConnection.mm

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ @implementation RCTPackagerConnection {
4040
std::mutex _mutex; // protects all ivars
4141
RCTReconnectingWebSocket *_socket;
4242
BOOL _socketConnected;
43-
NSString *_jsLocationForSocket;
43+
NSString *_serverHostForSocket;
4444
id _bundleURLChangeObserver;
4545
uint32_t _nextToken;
4646
std::vector<Registration<RCTNotificationHandler>> _notificationRegistrations;
@@ -62,8 +62,8 @@ - (instancetype)init
6262
{
6363
if (self = [super init]) {
6464
_nextToken = 1; // Prevent randomly erasing a handler if you pass a bogus 0 token
65-
_jsLocationForSocket = [RCTBundleURLProvider sharedSettings].jsLocation;
66-
_socket = socketForLocation(_jsLocationForSocket);
65+
_serverHostForSocket = [[RCTBundleURLProvider sharedSettings] packagerServerHost];
66+
_socket = socketForLocation(_serverHostForSocket);
6767
_socket.delegate = self;
6868
[_socket start];
6969

@@ -79,10 +79,10 @@ - (instancetype)init
7979
return self;
8080
}
8181

82-
static RCTReconnectingWebSocket *socketForLocation(NSString *const jsLocation)
82+
static RCTReconnectingWebSocket *socketForLocation(NSString *const serverHost)
8383
{
8484
NSURLComponents *const components = [NSURLComponents new];
85-
components.host = jsLocation ?: @"localhost";
85+
components.host = serverHost ?: @"localhost";
8686
components.scheme = @"http";
8787
components.port = @(kRCTBundleURLProviderDefaultPort);
8888
components.path = @"/message";
@@ -118,15 +118,15 @@ - (void)bundleURLSettingsChanged
118118
return; // already stopped
119119
}
120120

121-
NSString *const jsLocation = [RCTBundleURLProvider sharedSettings].jsLocation;
122-
if ([jsLocation isEqual:_jsLocationForSocket]) {
121+
NSString *const serverHost = [[RCTBundleURLProvider sharedSettings] packagerServerHost];
122+
if ([serverHost isEqual:_serverHostForSocket]) {
123123
return; // unchanged
124124
}
125125

126126
_socket.delegate = nil;
127127
[_socket stop];
128-
_jsLocationForSocket = jsLocation;
129-
_socket = socketForLocation(jsLocation);
128+
_serverHostForSocket = serverHost;
129+
_socket = socketForLocation(serverHost);
130130
_socket.delegate = self;
131131
[_socket start];
132132
}

0 commit comments

Comments
 (0)