Skip to content
11 changes: 5 additions & 6 deletions apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ export class RoomListViewViewModel
// Update roomsMap immediately before clearing VMs
this.updateRoomsMap(this.roomsResult);

// Clear view models since room list changed
this.clearViewModels();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the flip side of this is that some of these VMs will had around int he map until removed. But as you said when the visible rooms change they will be cleaned up.


this.updateRoomListData();
};

Expand Down Expand Up @@ -291,11 +288,13 @@ export class RoomListViewViewModel

const newSpaceId = this.roomsResult.spaceId;

// Clear view models since room list structure changed
this.clearViewModels();

// Detect space change
if (oldSpaceId !== newSpaceId) {
// Clear view models when the space changes
// We only want to do this on space changes, not on regular list updates, to preserve view models when possible
// The view models are disposed when scrolling out of view (handled by updateVisibleRooms)
this.clearViewModels();

// Space changed - get the last selected room for the new space to prevent flicker
const lastSelectedRoom = SpaceStore.instance.getLastSelectedRoomIdForSpace(newSpaceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Please see LICENSE files in the repository root for full details.
*/

import React, { type JSX, useId, useState } from "react";
import React, { type JSX, memo, useId, useState } from "react";
import { ChatFilter, IconButton } from "@vector-im/compound-web";
import ChevronDownIcon from "@vector-im/compound-design-tokens/assets/web/icons/chevron-down";

Expand Down Expand Up @@ -53,11 +53,11 @@ export interface RoomListPrimaryFiltersProps {
* The primary filters component for the room list.
* Displays a collapsible list of filters with expand/collapse functionality.
*/
export const RoomListPrimaryFilters: React.FC<RoomListPrimaryFiltersProps> = ({
export const RoomListPrimaryFilters = memo(function RoomListPrimaryFilters({
filterIds,
activeFilterId,
onToggleFilter,
}): JSX.Element | null => {
}: RoomListPrimaryFiltersProps): JSX.Element | null {
const id = useId();
const [isExpanded, setIsExpanded] = useState(false);

Expand Down Expand Up @@ -113,4 +113,4 @@ export const RoomListPrimaryFilters: React.FC<RoomListPrimaryFiltersProps> = ({
</Flex>
</Flex>
);
};
});
Loading