diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index e57184604c5..b6591bc2b7e 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -844,7 +844,7 @@ export class RoomView extends React.Component { case 'reply_to_event': if (!this.unmounted && this.state.searchResults && - payload.event.getRoomId() === this.state.roomId && + payload.event?.getRoomId() === this.state.roomId && payload.context === TimelineRenderingType.Search ) { this.onCancelSearchClick(); diff --git a/src/stores/RoomViewStore.tsx b/src/stores/RoomViewStore.tsx index d6ee527f8bd..e7f5e2ecb23 100644 --- a/src/stores/RoomViewStore.tsx +++ b/src/stores/RoomViewStore.tsx @@ -201,7 +201,7 @@ class RoomViewStore extends Store { // this can happen when performing a search across all rooms. Persist the data from this event for // both room and search timeline rendering types, search will get auto-closed by RoomView at this time. if ([TimelineRenderingType.Room, TimelineRenderingType.Search].includes(payload.context)) { - if (payload.event?.getRoomId() !== this.state.roomId) { + if (payload.event && payload.event.getRoomId() !== this.state.roomId) { dis.dispatch({ action: Action.ViewRoom, room_id: payload.event.getRoomId(),