Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash when insert nil value into a dictionary #30066

6 changes: 5 additions & 1 deletion React/CoreModules/RCTWebSocketModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
NSNumber *socketID = [webSocket reactTag];
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
[self sendEventWithName:@"websocketFailed" body:@{@"message" : error.localizedDescription, @"id" : socketID}];
NSDictionary *body = @{
@"message" : error.localizedDescription ?: @"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say something like "undefined" instead of empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment. I updated the error message to Undefined, error is nil.
Please let me know if you have any further feedback.

@"id" : socketID ?: @(-1)
};
[self sendEventWithName:@"websocketFailed" body:body];
}

- (void)webSocket:(RCTSRWebSocket *)webSocket
Expand Down