-
Notifications
You must be signed in to change notification settings - Fork 362
Description
Hello, I'm writing on behalf of the Citadel product developed by ERCOM.
Add an update type or diff field to the RoomInfoListener callback to enable efficient client-side updates and prevent unnecessary re-renders.
Description
Currently, the RoomInfoListener callback provides the full RoomInfo object whenever any property of the room changes.
interface RoomInfoListener {
call(info: RoomInfo): Promise<void>;
}The Problem:
The client receives the entire RoomInfo object but has no way of knowing what specifically changed (e.g., did the name change? the avatar? the unread count? or just the power levels?).
To prevent unnecessary React re-renders, the client currently has to manually compare every single field against its local state:
// Current inefficient client logic
if (newMetadata.name !== metadata.name ||
newMetadata.topic !== metadata.topic ||
newMetadata.avatar !== metadata.avatar ||
newMetadata.numUnreadMessages !== metadata.numUnreadMessages) {
// Update state...
}This is inefficient because:
- Performance: Deep comparison of objects (especially large ones like
powerLevelsor member lists) is expensive on the main thread. - Complexity: Client code becomes bloated with manual diffing logic.
- Over subscription: We might trigger heavy operations (like re-fetching the member list) when only a trivial field (like a typing notification or unread count) changed.
Suggested Solution
Please enhance the RoomInfoListener to include an updateType or changedFields property.
Option A: Update Type Enum
Provide a specific tag indicating the reason for the update.
const RoomInfoUpdateType = {
Name: 'Name',
Topic: 'Topic',
Avatar: 'Avatar',
UnreadCount: 'UnreadCount',
Members: 'Members',
PowerLevels: 'PowerLevels',
...
} as const;
type RoomInfoUpdateType = typeof RoomInfoUpdateType[keyof typeof RoomInfoUpdateType];
interface RoomInfoUpdate {
info: RoomInfo;
type: RoomInfoUpdateType; // What changed?
}Option B: Changed Fields Mask
Provide a bitmask or list of fields that changed.
interface RoomInfoUpdate {
info: RoomInfo;
changes: ["name", "numUnreadMessages"]; // Array of changed property names
}Acceptance Criteria
- The
RoomInfoListenercallback provides context on what changed. - Clients can switch on the update type to selectively update only the relevant parts of their state (e.g., update unread badge without re-rendering the room header).
Impact
- Significant Performance Gain: Clients can skip expensive checks (like member list diffing) when only simple metadata changes.
- Cleaner Code: Removes the need for manual field-by-field comparison in the UI layer.
- Reduced Re-renders: React components will only re-render when data they actually care about changes.
```# Add an update type or diff field to theRoomInfoListenercallback to enable efficient client-side updates and prevent unnecessary re-renders.