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

Prevent soft crash around room list header context menu when space changes #8289

Merged
merged 4 commits into from
Apr 12, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/views/rooms/RoomListHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ const RoomListHeader = ({ onVisibilityChange }: IProps) => {
}
});

const canShowMainMenu = activeSpace || spaceKey === MetaSpace.Home;

useEffect(() => {
if (mainMenuDisplayed && !canShowMainMenu) {
// Space changed under us and we no longer has a main menu to draw
closeMainMenu();
}
}, [closeMainMenu, canShowMainMenu, mainMenuDisplayed]);

// we pass null for the queryLength to inhibit the metrics hook for when there is no filterCondition
useWebSearchMetrics(count, filterCondition ? filterCondition.search.length : null, false);

Expand Down Expand Up @@ -168,7 +177,7 @@ const RoomListHeader = ({ onVisibilityChange }: IProps) => {
const canShowPlusMenu = canCreateRooms || canExploreRooms || activeSpace;

let contextMenu: JSX.Element;
if (mainMenuDisplayed) {
if (mainMenuDisplayed && mainMenuHandle.current) {
let ContextMenuComponent;
if (activeSpace) {
ContextMenuComponent = SpaceContextMenu;
Expand Down Expand Up @@ -364,7 +373,7 @@ const RoomListHeader = ({ onVisibilityChange }: IProps) => {
.join("\n");

let contextMenuButton: JSX.Element = <div className="mx_RoomListHeader_contextLessTitle">{ title }</div>;
if (activeSpace || spaceKey === MetaSpace.Home) {
if (canShowMainMenu) {
contextMenuButton = <ContextMenuTooltipButton
inputRef={mainMenuHandle}
onClick={openMainMenu}
Expand Down