Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3397416
D13298.id44061.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D13298.id44061.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D13298: [lib] Avoid useless updateRelationships call when logged out in handleFarcasterMutuals
Attached
Detach File
Event Timeline
Log In to Comment