Skip to content

Commit

Permalink
Handle all incoming Inspector messages on main thread (facebook#41503)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [Internal]

Updates RCTInspectorPackagerConnection to dispatch all messages on the main thread (which is SocketRocket's default behaviour). This is in support of a new CDP implementation in React Native that will strictly assume it's called on the main thread (thus avoiding the need for explicit locking in many places).

Reviewed By: javache

Differential Revision: D51346659
  • Loading branch information
motiz88 authored and facebook-github-bot committed Nov 21, 2023
1 parent 781b637 commit ab5b769
Showing 1 changed file with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ @interface RCTInspectorPackagerConnection () <SRWebSocketDelegate> {
NSURL *_url;
NSMutableDictionary<NSString *, RCTInspectorLocalConnection *> *_inspectorConnections;
SRWebSocket *_webSocket;
dispatch_queue_t _jsQueue;
BOOL _closed;
BOOL _suppressConnectionErrors;
RCTBundleStatusProvider _bundleStatusProvider;
Expand Down Expand Up @@ -57,7 +56,6 @@ - (instancetype)initWithURL:(NSURL *)url
if (self = [super init]) {
_url = url;
_inspectorConnections = [NSMutableDictionary new];
_jsQueue = dispatch_queue_create("com.facebook.react.WebSocketExecutor", DISPATCH_QUEUE_SERIAL);
}
return self;
}
Expand Down Expand Up @@ -247,7 +245,6 @@ - (void)connect
// timeouts, but our previous class, RCTSRWebSocket didn't have the same
// implemented options. Might be worth reinvestigating for SRWebSocket?
_webSocket = [[SRWebSocket alloc] initWithURL:_url];
[_webSocket setDelegateDispatchQueue:_jsQueue];
_webSocket.delegate = self;
[_webSocket open];
}
Expand Down Expand Up @@ -282,7 +279,7 @@ - (void)closeQuietly
- (void)sendToPackager:(NSDictionary *)messageObject
{
__weak RCTInspectorPackagerConnection *weakSelf = self;
dispatch_async(_jsQueue, ^{
dispatch_async(dispatch_get_main_queue(), ^{
RCTInspectorPackagerConnection *strongSelf = weakSelf;
if (strongSelf && !strongSelf->_closed) {
NSError *error;
Expand Down

0 comments on commit ab5b769

Please sign in to comment.