Skip to content

Commit

Permalink
[lib] Prevent SET_AUX_USER_FIDS from overwriting state when no changes
Browse files Browse the repository at this point in the history
Summary:
I was seeing a React render cycle after introducing D13443. When I updated `useUpdateRelationships` to depend on `auxUserInfos`, it caused the hook to get generated when `auxUserInfos` changed. This caused the effect in `FarcasterDataHandler` to run again, which resulted in `auxUserInfos` changing again.

To break this loop, this diff makes sure we only change `auxUserInfos` if there are actual changes.

Depends on D13443

Test Plan: Confirm that the React render cycle no longer prevents me from logging in as the `commeth` account

Reviewers: will, varun

Reviewed By: will

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13453
  • Loading branch information
Ashoat committed Sep 24, 2024
1 parent c93f6bc commit b2d47db
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/reducers/aux-user-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,27 @@ function reduceAuxUserStore(
const replaceOperations: ReplaceAuxUserInfoOperation[] = [];
for (const userID in state.auxUserInfos) {
if (
state.auxUserInfos[userID].fid !== null &&
!toUpdateUserIDs.has(userID)
state.auxUserInfos[userID].fid === null ||
toUpdateUserIDs.has(userID)
) {
replaceOperations.push({
type: 'replace_aux_user_info',
payload: {
id: userID,
auxUserInfo: {
...state.auxUserInfos[userID],
fid: null,
},
},
});
continue;
}
replaceOperations.push({
type: 'replace_aux_user_info',
payload: {
id: userID,
auxUserInfo: {
...state.auxUserInfos[userID],
fid: null,
},
},
});
}
for (const farcasterUser of action.payload.farcasterUsers) {
const existingAuxUserInfo = state.auxUserInfos[farcasterUser.userID];
if (existingAuxUserInfo?.fid === farcasterUser.farcasterID) {
continue;
}
replaceOperations.push({
type: 'replace_aux_user_info',
payload: {
Expand Down

0 comments on commit b2d47db

Please sign in to comment.