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

Commit e762a69

Browse files
authored
Fix bug with useRoomHierarchy tight-looping loadMore on error (#7893)
1 parent 130bd6a commit e762a69

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/components/structures/SpaceHierarchy.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,10 @@ export const useRoomHierarchy = (space: Room): {
490490
} => {
491491
const [rooms, setRooms] = useState<IHierarchyRoom[]>([]);
492492
const [hierarchy, setHierarchy] = useState<RoomHierarchy>();
493-
const [error, setError] = useState<Error>();
493+
const [error, setError] = useState<Error | undefined>();
494494

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

512513
const loadMore = useCallback(async (pageSize?: number) => {
513-
if (hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport) return;
514+
if (hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport || error) return;
514515
await hierarchy.load(pageSize).catch(setError);
515516
setRooms(hierarchy.rooms);
516-
}, [hierarchy]);
517+
}, [error, hierarchy]);
517518

518519
const loading = hierarchy?.loading ?? true;
519520
return { loading, rooms, hierarchy, loadMore, error };

0 commit comments

Comments
 (0)