From 8c86140910e165e889134f15ac4ba791b4c36131 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Wed, 4 Dec 2024 20:52:18 -0600 Subject: [PATCH] fix(#141): peer verification stability regression --- src/components/Room/usePeerVerification.ts | 3 +++ src/components/Room/useRoom.ts | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/Room/usePeerVerification.ts b/src/components/Room/usePeerVerification.ts index f277ef464..f3f7a1f5b 100644 --- a/src/components/Room/usePeerVerification.ts +++ b/src/components/Room/usePeerVerification.ts @@ -134,6 +134,7 @@ export const usePeerVerification = ({ // getDisplayUsername). const [scheduledPeerToVerify, setScheduledPeerToVerify] = useState(null) + useEffect(() => { if (scheduledPeerToVerify === null || isDirectMessageRoom) return @@ -143,6 +144,8 @@ export const usePeerVerification = ({ // NOTE: END HACKY WORKAROUND const verifyPeer = (peer: Peer) => { + if (isDirectMessageRoom) return + setScheduledPeerToVerify(peer) } diff --git a/src/components/Room/useRoom.ts b/src/components/Room/useRoom.ts index 817865602..31fba73fe 100644 --- a/src/components/Room/useRoom.ts +++ b/src/components/Room/useRoom.ts @@ -296,7 +296,7 @@ export function useRoom( verificationTimer: null, } - setPeerList([...peerList, newPeer]) + setPeerList(prev => [...prev, newPeer]) sendTypingStatusChange({ isTyping }, peerId) verifyPeer(newPeer) } else { @@ -304,10 +304,13 @@ export function useRoom( peerList[peerIndex].customUsername || getPeerName(userId) const newUsername = customUsername || getPeerName(userId) - const newPeerList = [...peerList] - const newPeer = { ...newPeerList[peerIndex], userId, customUsername } - newPeerList[peerIndex] = newPeer - setPeerList(newPeerList) + setPeerList(prev => { + const newPeerList = [...prev] + const newPeer = { ...newPeerList[peerIndex], userId, customUsername } + newPeerList[peerIndex] = newPeer + + return newPeerList + }) if (oldUsername !== newUsername) { showAlert(`${oldUsername} is now ${newUsername}`) @@ -471,9 +474,12 @@ export function useRoom( ) if (doesPeerExist) { - const peerListClone = [...peerList] - peerListClone.splice(peerIndex, 1) - setPeerList(peerListClone) + setPeerList(prev => { + const peerListClone = [...prev] + peerListClone.splice(peerIndex, 1) + + return peerListClone + }) } }) }