diff --git a/src/components/views/dialogs/LeaveSpaceDialog.tsx b/src/components/views/dialogs/LeaveSpaceDialog.tsx index 74fec7eae2..804987f53a 100644 --- a/src/components/views/dialogs/LeaveSpaceDialog.tsx +++ b/src/components/views/dialogs/LeaveSpaceDialog.tsx @@ -41,7 +41,14 @@ const isOnlyAdmin = (room: Room): boolean => { }; const LeaveSpaceDialog: React.FC = ({ space, onFinished }) => { - const spaceChildren = useMemo(() => SpaceStore.instance.getChildren(space.roomId), [space.roomId]); + const spaceChildren = useMemo(() => { + const roomSet = new Set(SpaceStore.instance.getSpaceFilteredRoomIds(space.roomId)); + SpaceStore.instance.traverseSpace(space.roomId, spaceId => { + if (space.roomId === spaceId) return; // skip the root node + roomSet.add(spaceId); + }, false); + return Array.from(roomSet).map(roomId => space.client.getRoom(roomId)).filter(Boolean); + }, [space]); const [roomsToLeave, setRoomsToLeave] = useState([]); const selectedRooms = useMemo(() => new Set(roomsToLeave), [roomsToLeave]);