Room list: fix expanded/collapse state of sections (#33074)

* fix: section being empty in flat list mode

When switching space (or removing a section later), if the Chat section
is collpased and the room list is in flat list mode in the other space,
the room list is empty.

The fix forces the section to be in expanded state if in flat list mode

* fix: store section expanded state by space
This commit is contained in:
Florian Duros
2026-04-08 14:44:52 +01:00
committed by GitHub
parent ce498ef983
commit 121c2d18e9
4 changed files with 106 additions and 8 deletions
@@ -806,10 +806,10 @@ describe("RoomListViewModel", () => {
expect(favSection!.roomIds).toEqual([]);
});
it("should preserve section collapse state across space changes", () => {
it("should track section collapse state per space", () => {
viewModel = new RoomListViewModel({ client: matrixClient });
// Collapse favourites
// Collapse favourites in the home space
const favHeader = viewModel.getSectionHeaderViewModel(DefaultTagID.Favourite);
favHeader.onClick();
@@ -828,15 +828,37 @@ describe("RoomListViewModel", () => {
RoomListStoreV3.instance.emit(RoomListStoreV3Event.ListsUpdate);
const snapshot = viewModel.getSnapshot();
// Favourites should still be collapsed even after the space change
const favSection = snapshot.sections.find((s) => s.id === DefaultTagID.Favourite);
let snapshot = viewModel.getSnapshot();
// Favourites should be expanded in the new space (per-space state)
let favSection = snapshot.sections.find((s) => s.id === DefaultTagID.Favourite);
expect(favSection).toBeDefined();
expect(favSection!.roomIds).toEqual(["!spacefav:server"]);
// Other sections should also be expanded
let chatsSection = snapshot.sections.find((s) => s.id === CHATS_TAG);
expect(chatsSection!.roomIds).toEqual(["!spacereg:server"]);
// Switch back to home space
jest.spyOn(RoomListStoreV3.instance, "getSortedRoomsInActiveSpace").mockReturnValue({
spaceId: "home",
sections: [
{ tag: DefaultTagID.Favourite, rooms: [favRoom1, favRoom2] },
{ tag: CHATS_TAG, rooms: [regularRoom1] },
{ tag: DefaultTagID.LowPriority, rooms: [] },
],
});
RoomListStoreV3.instance.emit(RoomListStoreV3Event.ListsUpdate);
snapshot = viewModel.getSnapshot();
// Favourites should still be collapsed in the home space
favSection = snapshot.sections.find((s) => s.id === DefaultTagID.Favourite);
expect(favSection).toBeDefined();
expect(favSection!.roomIds).toEqual([]);
// Other sections should remain expanded
const chatsSection = snapshot.sections.find((s) => s.id === CHATS_TAG);
expect(chatsSection!.roomIds).toEqual(["!spacereg:server"]);
// Chats should be expanded
chatsSection = snapshot.sections.find((s) => s.id === CHATS_TAG);
expect(chatsSection!.roomIds).toEqual(["!reg1:server"]);
});
it("should apply filters across all sections", () => {