diff --git a/lib/shared/community-utils.js b/lib/shared/community-utils.js --- a/lib/shared/community-utils.js +++ b/lib/shared/community-utils.js @@ -32,6 +32,7 @@ import type { ThreadSubscription } from '../types/subscription-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; +import type { ThreadJoinPayload } from '../types/thread-types.js'; import { useCurrentUserFID } from '../utils/farcaster-utils.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useDispatch, useSelector } from '../utils/redux-utils.js'; @@ -324,9 +325,14 @@ } }, [isAuthenticated, ongoingJoinData, setStep, step]); + const threadJoinPromiseRef = React.useRef>(null); React.useEffect(() => { void (async () => { - if (!ongoingJoinData || step !== 'join_community') { + if ( + !ongoingJoinData || + step !== 'join_community' || + threadJoinPromiseRef.current + ) { return; } const communityThreadID = ongoingJoinData.communityID; @@ -344,6 +350,7 @@ inviteLinkSecret: inviteSecret, defaultSubscription, }); + threadJoinPromiseRef.current = joinThreadPromise; void dispatchActionPromise(joinThreadActionTypes, joinThreadPromise); try { @@ -355,6 +362,8 @@ ); ongoingJoinData.reject(); setOngoingJoinData(null); + } finally { + threadJoinPromiseRef.current = null; } })(); }, [