Fix soft crash around space hierarchy changing between spaces (#9191)

pull/28217/head
Michael Telatynski 2022-08-16 15:39:10 +01:00 committed by GitHub
parent 6f2c761fb4
commit d0d91599a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -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,
}; };