mirror of https://github.com/vector-im/riot-web
Fix soft crash around space hierarchy changing between spaces (#9191)
parent
6f2c761fb4
commit
d0d91599a9
|
@ -504,7 +504,7 @@ export const useRoomHierarchy = (space: Room): {
|
||||||
loadMore(pageSize?: number): Promise<void>;
|
loadMore(pageSize?: number): Promise<void>;
|
||||||
} => {
|
} => {
|
||||||
const [rooms, setRooms] = useState<IHierarchyRoom[]>([]);
|
const [rooms, setRooms] = useState<IHierarchyRoom[]>([]);
|
||||||
const [hierarchy, setHierarchy] = useState<RoomHierarchy>();
|
const [roomHierarchy, setHierarchy] = useState<RoomHierarchy>();
|
||||||
const [error, setError] = useState<Error | undefined>();
|
const [error, setError] = useState<Error | undefined>();
|
||||||
|
|
||||||
const resetHierarchy = useCallback(() => {
|
const resetHierarchy = useCallback(() => {
|
||||||
|
@ -526,15 +526,21 @@ export const useRoomHierarchy = (space: Room): {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const loadMore = useCallback(async (pageSize?: number) => {
|
const loadMore = useCallback(async (pageSize?: number) => {
|
||||||
if (hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport || error) return;
|
if (roomHierarchy.loading || !roomHierarchy.canLoadMore || roomHierarchy.noSupport || error) return;
|
||||||
await hierarchy.load(pageSize).catch(setError);
|
await roomHierarchy.load(pageSize).catch(setError);
|
||||||
setRooms(hierarchy.rooms);
|
setRooms(roomHierarchy.rooms);
|
||||||
}, [error, hierarchy]);
|
}, [error, roomHierarchy]);
|
||||||
|
|
||||||
|
// Only return the hierarchy if it is for the space requested
|
||||||
|
let hierarchy = roomHierarchy;
|
||||||
|
if (hierarchy?.root !== space) {
|
||||||
|
hierarchy = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loading: hierarchy?.loading ?? true,
|
loading: hierarchy?.loading ?? true,
|
||||||
rooms,
|
rooms,
|
||||||
hierarchy: hierarchy?.root === space ? hierarchy : undefined,
|
hierarchy,
|
||||||
loadMore,
|
loadMore,
|
||||||
error,
|
error,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue