Skip to content

Commit 0c89ab9

Browse files
authored
Merge pull request matrix-org#3738 from matrix-org/t3chguy/null-guard-useIsEncrypted
Fix UserInfo exploding without a room being passed to it
2 parents 590ef79 + c1133eb commit 0c89ab9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/components/views/right_panel/UserInfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ function openDMForUser(matrixClient, userId) {
109109
}
110110

111111
function useIsEncrypted(cli, room) {
112-
const [isEncrypted, setIsEncrypted] = useState(cli.isRoomEncrypted(room.roomId));
112+
const [isEncrypted, setIsEncrypted] = useState(room ? cli.isRoomEncrypted(room.roomId) : undefined);
113113

114114
const update = useCallback((event) => {
115115
if (event.getType() === "m.room.encryption") {
116116
setIsEncrypted(cli.isRoomEncrypted(room.roomId));
117117
}
118118
}, [cli, room]);
119-
useEventEmitter(room.currentState, "RoomState.events", update);
119+
useEventEmitter(room ? room.currentState : undefined, "RoomState.events", update);
120120
return isEncrypted;
121121
}
122122

src/hooks/useEventEmitter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export const useEventEmitter = (emitter, eventName, handler) => {
2828

2929
useEffect(
3030
() => {
31+
// allow disabling this hook by passing a falsy emitter
32+
if (!emitter) return;
33+
3134
// Create event listener that calls handler function stored in ref
3235
const eventListener = event => savedHandler.current(event);
3336

0 commit comments

Comments
 (0)