Skip to content

Commit

Permalink
fix(presence): fix presence not synchronizing states properly (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
timadevelop authored Nov 28, 2024
1 parent 382393c commit f84b454
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/usePresence/usePresence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export function usePresence<PayloadType, MetasType = Metas>(
channel.on('presence_state', (newState) => {
_setPresence((prevState) => {
if (Object.keys(prevState).length === 0) return newState;
return Presence.syncState(prevState, newState);
const nextState = {...prevState};
return Presence.syncState(nextState, newState);
});
});

channel.on('presence_diff', (newDiff) => {
_setPresence((prevState) => {
if (Object.keys(prevState).length === 0) return prevState;
return Presence.syncDiff(prevState, newDiff);
// Note that prevState might be empty, we still need to sync it
const nextState = {...prevState};
return Presence.syncDiff(nextState, newDiff);
});
});

Expand Down

0 comments on commit f84b454

Please sign in to comment.