fix: deliver live role updates to the UI
Merged
GG
19d ago+131+131+012345678901234567890123456789-32-32-01234567890123456789
Proposed changes (including videos or screenshots)
Role changes streamed through notify-logged (roles-change) never reached the components showing them, so granting or revoking a role only showed up after a reload. Three bugs in useRoomRolesQuery / useUserRolesQuery:
- Cache mutated in place. The updaters replaced
data[index]on the cached array and then returned a copy. React Query's structural sharing compared the (already mutated) old data with the new one, found them deep-equal, kept the old reference, and never notified observers. Records are now replaced withmap, never mutated. - Room role removals dropped. The
removedbranch returned early on!!scope, but every room role carries a scope, so no removal was ever applied. - Changes from other rooms leaked in. Neither branch checked that the event's scope matched the room the cache belongs to.
Extracted from #41650 (user information redesign), where @ivans-netto found and fixed these. Stacked on #42500; #41650 is stacked on top of this one.
Issue(s)
Steps to test or reproduce
- Open a room and the members list (or a message from a member, to see the role tags).
- In another session, set that member as moderator, then remove the moderator role.
- Before: nothing changes until reload. After: the role appears and disappears live.
- Granting a role in a different room doesn't change the current room's member roles.
Further comments
useRoomRolesQuery.spec.ts covers the three cases. All three fail against the previous implementation: the "added" case asserts a new data reference, which is what makes subscribed components re-render.
Summary by CodeRabbit
-
Bug Fixes
- Room and workspace role changes are reflected in live updates, with additions and removals shown correctly.
- Room-specific role updates no longer affect role information in unrelated rooms.
- Duplicate role entries are prevented when roles are added.
-
Improvements
- User cards, user information, and time and date formatting features are now shared across the app.