mirror of
https://github.com/facebook/react-native.git
synced 2024-11-21 22:10:14 +00:00
fix r
& d
not working from Metro sometimes (#47624)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47624 Changelog: [iOS][Fixed] - fix `r` & `d` not working from Metro sometimes While investigating these bugs, I've come across some cases where `r` (Reload) & `d` (Open Dev Menu) not working in Metro. * T206141946 / [WP: Reconnecting dev tools does not work after restarting the app](https://fb.workplace.com/groups/rn.debugger.feedback/posts/1107620434125533) * T206754760 / [WP: Can't launch DevTools from Metro sometimes](https://fb.workplace.com/groups/rn.debugger.feedback/posts/1112235073664069/) This is because when we 1. Start app without Metro 1. Start Metro 1. Reload from Dev Menu (rage shake) `RCTPackagerConnection` did not get notified about the change in bundle URL. It'd stay "listening" to the commands from the local bundle instead of Metro . Reviewed By: robhogan Differential Revision: D65973309 fbshipit-source-id: a67a58b405bb78dfe56b814f2ec0bbee9e530e46
This commit is contained in:
parent
74ed831a33
commit
9a60038a40
@ -20,6 +20,7 @@
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTPackagerClient.h>
|
||||
#import <React/RCTReconnectingWebSocket.h>
|
||||
#import <React/RCTReloadCommand.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
#if RCT_DEV
|
||||
@ -44,6 +45,7 @@ struct Registration {
|
||||
NSString *_serverHostPortForSocket;
|
||||
NSString *_serverSchemeForSocket;
|
||||
id _bundleURLChangeObserver;
|
||||
id _reloadWithPotentiallyNewURLObserver;
|
||||
uint32_t _nextToken;
|
||||
std::vector<Registration<RCTNotificationHandler>> _notificationRegistrations;
|
||||
std::vector<Registration<RCTRequestHandler>> _requestRegistrations;
|
||||
@ -78,6 +80,13 @@ struct Registration {
|
||||
usingBlock:^(NSNotification *_Nonnull __unused note) {
|
||||
[weakSelf bundleURLSettingsChanged];
|
||||
}];
|
||||
_reloadWithPotentiallyNewURLObserver =
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:RCTTriggerReloadCommandNotification
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *_Nonnull __unused note) {
|
||||
[weakSelf bundleURLSettingsChanged];
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -119,6 +128,8 @@ static RCTReconnectingWebSocket *socketForLocation(NSString *const serverHostPor
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:_bundleURLChangeObserver];
|
||||
_bundleURLChangeObserver = nil;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:_reloadWithPotentiallyNewURLObserver];
|
||||
_reloadWithPotentiallyNewURLObserver = nil;
|
||||
_socketConnected = NO;
|
||||
[_socket stop];
|
||||
_socket = nil;
|
||||
|
Loading…
Reference in New Issue
Block a user