From 001e725869289024f11449277c1d99785d3c3ad2 Mon Sep 17 00:00:00 2001 From: Ashoat Tevosyan Date: Mon, 30 Sep 2024 11:39:41 -0400 Subject: [PATCH] [lib] Allow multiple simultaneous calls to useUpdateRelationships from a single component Summary: In a [final revision](https://phab.comm.dev/D13443?vs=44493&id=44495#toc) to D13443 before landing, I added some code to limit the hook to one ongoing operation per component where the hook is used. I did this because at the time, the hook relied on a piece of React state, and could not support multiple simultaneous calls. Later in D13496, I got rid of this React state, but I didn't reevaluate whether this limitation could be removed as well. Given that we no longer have any issues supporting multiple simultaneous calls, I think it's best to remove this limitation. It could cause issues if `useUpdateRelationships` is called with a new user ID before the previous call completes. In that case, this code would cause the new user ID to be ignored. Test Plan: I never really tested the original concern that caused me to add this limitation. I think it's safe to land this without much testing, since I had tested the functionality because I introduced this limitation and it worked correctly Reviewers: kamil, varun, will Reviewed By: will Subscribers: tomek Differential Revision: https://phab.comm.dev/D13521 --- lib/hooks/relationship-hooks.js | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/lib/hooks/relationship-hooks.js b/lib/hooks/relationship-hooks.js index a79516d688..440ed805a3 100644 --- a/lib/hooks/relationship-hooks.js +++ b/lib/hooks/relationship-hooks.js @@ -228,9 +228,7 @@ function useUpdateRelationships(): ( ], ); - const [inProgress, setInProgress] = React.useState(false); - - const coreFunctionality = React.useCallback( + return React.useCallback( async (action: RelationshipAction, userIDs: $ReadOnlyArray) => { if ( action === relationshipActions.FRIEND || @@ -261,25 +259,6 @@ function useUpdateRelationships(): ( }, [updateRelationshipsAndSendRobotext, updateRelationships], ); - - return React.useCallback( - async (action: RelationshipAction, userIDs: $ReadOnlyArray) => { - if (inProgress) { - console.log( - 'updateRelationships called from same component before last call ' + - 'finished. ignoring', - ); - return {}; - } - setInProgress(true); - try { - return await coreFunctionality(action, userIDs); - } finally { - setInProgress(false); - } - }, - [inProgress, coreFunctionality], - ); } export { useUpdateRelationships };