Skip to content

Commit

Permalink
[lib] Allow multiple simultaneous calls to useUpdateRelationships fro…
Browse files Browse the repository at this point in the history
…m 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
  • Loading branch information
Ashoat committed Oct 1, 2024
1 parent 336252d commit 001e725
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions lib/hooks/relationship-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ function useUpdateRelationships(): (
],
);

const [inProgress, setInProgress] = React.useState<boolean>(false);

const coreFunctionality = React.useCallback(
return React.useCallback(
async (action: RelationshipAction, userIDs: $ReadOnlyArray<string>) => {
if (
action === relationshipActions.FRIEND ||
Expand Down Expand Up @@ -261,25 +259,6 @@ function useUpdateRelationships(): (
},
[updateRelationshipsAndSendRobotext, updateRelationships],
);

return React.useCallback(
async (action: RelationshipAction, userIDs: $ReadOnlyArray<string>) => {
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 };

0 comments on commit 001e725

Please sign in to comment.