Page MenuHomePhabricator

D10973.id36960.diff
No OneTemporary

D10973.id36960.diff

diff --git a/lib/identity-search/identity-search-context.js b/lib/identity-search/identity-search-context.js
--- a/lib/identity-search/identity-search-context.js
+++ b/lib/identity-search/identity-search-context.js
@@ -38,6 +38,13 @@
const socket = React.useRef<?WebSocket>(null);
const heartbeatTimeoutID = React.useRef<?TimeoutID>();
+ const previousAuthMessage = React.useRef<?AuthMessage>(null);
+ const memoizedAuthMessage = React.useMemo(
+ () => authMessage,
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ [authMessage?.deviceID, authMessage?.accessToken, authMessage?.userID],
+ );
+
const stopHeartbeatTimeout = React.useCallback(() => {
if (heartbeatTimeoutID.current) {
clearTimeout(heartbeatTimeoutID.current);
@@ -54,6 +61,21 @@
}, [stopHeartbeatTimeout]);
React.useEffect(() => {
+ const isSocketActive =
+ socket.current?.readyState === WebSocket.OPEN ||
+ socket.current?.readyState === WebSocket.CONNECTING;
+
+ const authMessageChanged =
+ memoizedAuthMessage !== previousAuthMessage.current;
+ if (authMessageChanged) {
+ previousAuthMessage.current = memoizedAuthMessage;
+ }
+
+ if ((!authMessage || authMessageChanged) && isSocketActive) {
+ socket.current?.close();
+ return;
+ }
+
if (connected || !authMessage) {
return;
}
@@ -127,7 +149,13 @@
};
socket.current = identitySearchSocket;
- }, [connected, authMessage, resetHeartbeatTimeout, stopHeartbeatTimeout]);
+ }, [
+ connected,
+ authMessage,
+ resetHeartbeatTimeout,
+ stopHeartbeatTimeout,
+ memoizedAuthMessage,
+ ]);
const addListener = React.useCallback(
(listener: IdentitySearchSocketListener) => {

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 4:39 AM (21 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675306
Default Alt Text
D10973.id36960.diff (1 KB)

Event Timeline