From e762a6947d5a3c0d77075f6e512a5263c7fcd04c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 24 Feb 2022 22:52:04 +0000 Subject: [PATCH] Fix bug with useRoomHierarchy tight-looping loadMore on error (#7893) --- src/components/structures/SpaceHierarchy.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index 8ce911e0d4c..fb17fc6cc6c 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -490,9 +490,10 @@ export const useRoomHierarchy = (space: Room): { } => { const [rooms, setRooms] = useState([]); const [hierarchy, setHierarchy] = useState(); - const [error, setError] = useState(); + const [error, setError] = useState(); const resetHierarchy = useCallback(() => { + setError(undefined); const hierarchy = new RoomHierarchy(space, INITIAL_PAGE_SIZE); hierarchy.load().then(() => { if (space !== hierarchy.root) return; // discard stale results @@ -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 };