From 184c73cca46d85a3fe1da7b0a0f47e8c91d58285 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 9 Dec 2020 11:02:30 +0000 Subject: [PATCH 1/3] Throttle RoomState.members handler to improve performance Lazy Loading emits a RoomState.members for each member which in the case of a room like Matrix HQ means it happens over 8000 times in a very short span of time causing the UI to lock up. --- .../views/right_panel/RoomSummaryCard.tsx | 13 ++------ src/hooks/useRoomMembers.ts | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 src/hooks/useRoomMembers.ts diff --git a/src/components/views/right_panel/RoomSummaryCard.tsx b/src/components/views/right_panel/RoomSummaryCard.tsx index 4ce4b75f9b..3617def7aa 100644 --- a/src/components/views/right_panel/RoomSummaryCard.tsx +++ b/src/components/views/right_panel/RoomSummaryCard.tsx @@ -43,6 +43,7 @@ import RoomContext from "../../../contexts/RoomContext"; import {UIFeature} from "../../../settings/UIFeature"; import {ChevronFace, ContextMenuTooltipButton, useContextMenu} from "../../structures/ContextMenu"; import WidgetContextMenu from "../context_menus/WidgetContextMenu"; +import {useRoomMembers} from "../../../hooks/useRoomMembers"; interface IProps { room: Room; @@ -210,14 +211,6 @@ const onRoomSettingsClick = () => { defaultDispatcher.dispatch({ action: "open_room_settings" }); }; -const useMemberCount = (room: Room) => { - const [count, setCount] = useState(room.getJoinedMembers().length); - useEventEmitter(room.currentState, "RoomState.members", () => { - setCount(room.getJoinedMembers().length); - }); - return count; -}; - const RoomSummaryCard: React.FC = ({ room, onClose }) => { const cli = useContext(MatrixClientContext); @@ -251,12 +244,12 @@ const RoomSummaryCard: React.FC = ({ room, onClose }) => { ; - const memberCount = useMemberCount(room); + const members = useRoomMembers(room); return