diff --git a/apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts b/apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts index 093deba491..ed1c305796 100644 --- a/apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts +++ b/apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts @@ -25,6 +25,7 @@ import { RoomNotificationStateStore } from "../../stores/notifications/RoomNotif import { RoomListItemViewModel } from "./RoomListItemViewModel"; import { SdkContextClass } from "../../contexts/SDKContext"; import { hasCreateRoomRights } from "./utils"; +import { keepIfSame } from "../../utils/keepIfSame"; interface RoomListViewViewModelProps { client: MatrixClient; @@ -407,13 +408,16 @@ export class RoomListViewViewModel // Build the complete state atomically to ensure consistency // roomIds and roomListState must always be in sync const roomIds = this.roomIds; + + // Update filter keys - only update if they have actually changed to prevent unnecessary re-renders of the room list + const previousFilterKeys = this.snapshot.current.roomListState.filterKeys; + const newFilterKeys = this.roomsResult.filterKeys?.map((k) => String(k)); const roomListState: RoomListViewState = { activeRoomIndex, spaceId: this.roomsResult.spaceId, - filterKeys: this.roomsResult.filterKeys?.map((k) => String(k)), + filterKeys: keepIfSame(previousFilterKeys, newFilterKeys), }; - const filterIds = [...filterKeyToIdMap.values()]; const activeFilterId = this.activeFilter !== undefined ? filterKeyToIdMap.get(this.activeFilter) : undefined; const isRoomListEmpty = roomIds.length === 0; const isLoadingRooms = RoomListStoreV3.instance.isLoadingRooms; @@ -422,7 +426,6 @@ export class RoomListViewViewModel this.snapshot.merge({ isLoadingRooms, isRoomListEmpty, - filterIds, activeFilterId, roomListState, roomIds,