Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix bug with useRoomHierarchy tight-looping loadMore on error (#7893)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Feb 24, 2022
1 parent 130bd6a commit e762a69
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/structures/SpaceHierarchy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,10 @@ export const useRoomHierarchy = (space: Room): {
} => {
const [rooms, setRooms] = useState<IHierarchyRoom[]>([]);
const [hierarchy, setHierarchy] = useState<RoomHierarchy>();
const [error, setError] = useState<Error>();
const [error, setError] = useState<Error | undefined>();

const resetHierarchy = useCallback(() => {
setError(undefined);
const hierarchy = new RoomHierarchy(space, INITIAL_PAGE_SIZE);
hierarchy.load().then(() => {
if (space !== hierarchy.root) return; // discard stale results
Expand All @@ -510,10 +511,10 @@ export const useRoomHierarchy = (space: Room): {
}));

const loadMore = useCallback(async (pageSize?: number) => {
if (hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport) return;
if (hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport || error) return;
await hierarchy.load(pageSize).catch(setError);
setRooms(hierarchy.rooms);
}, [hierarchy]);
}, [error, hierarchy]);

const loading = hierarchy?.loading ?? true;
return { loading, rooms, hierarchy, loadMore, error };
Expand Down

0 comments on commit e762a69

Please sign in to comment.