Page MenuHomePhabricator

D13298.id44061.diff
No OneTemporary

D13298.id44061.diff

diff --git a/lib/components/farcaster-data-handler.react.js b/lib/components/farcaster-data-handler.react.js
--- a/lib/components/farcaster-data-handler.react.js
+++ b/lib/components/farcaster-data-handler.react.js
@@ -63,6 +63,15 @@
const prevCanQueryRef = React.useRef<?boolean>();
+ // It's possible for the user to log out while handleFarcasterMutuals below
+ // is running. It's not a big deal, but this can lead to a useless server call
+ // at the end. To avoid that useless server call, we want to check whether the
+ // user is logged in beforehand, but the value of loggedIn bound in the
+ // callback will be outdated. Instead, we can check this ref, which will be
+ // updated on every render.
+ const loggedInRef = React.useRef(loggedIn);
+ loggedInRef.current = loggedIn;
+
const handleFarcasterMutuals = React.useCallback(async () => {
const canQuery = isActive && !!fid && loggedIn;
if (canQuery === prevCanQueryRef.current) {
@@ -100,6 +109,10 @@
[(currentUserID: string)]: fid,
};
+ if (!loggedInRef.current) {
+ return;
+ }
+
void dispatchActionPromise(
updateRelationshipsActionTypes,
createThreadsAndRobotextForFarcasterMutuals(

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 2, 5:37 PM (18 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2608388
Default Alt Text
D13298.id44061.diff (1 KB)

Event Timeline