diff --git a/client/components/RoomForeword.js b/client/components/RoomForeword.js index 4e20ecce07e0f..aa0cd9c335cce 100644 --- a/client/components/RoomForeword.js +++ b/client/components/RoomForeword.js @@ -13,7 +13,7 @@ const RoomForeword = ({ _id: rid }) => { const user = useUser(); const room = useReactiveValue(useCallback(() => Rooms.findOne({ _id: rid }), [rid])); - if (room.t !== 'd') { + if (room?.t !== 'd') { return t('Start_of_conversation'); } diff --git a/client/views/room/providers/RoomProvider.tsx b/client/views/room/providers/RoomProvider.tsx index 50776ab538a39..30cf555fbe15c 100644 --- a/client/views/room/providers/RoomProvider.tsx +++ b/client/views/room/providers/RoomProvider.tsx @@ -20,11 +20,16 @@ const RoomProvider = ({ rid, children }: Props): JSX.Element => { const _room = useUserRoom(rid, fields) as unknown as IRoom; const room = uid ? subscription || _room : _room; - room._id = rid; - const context = useMemo(() => ({ - rid, - room: { ...room, name: roomTypes.getRoomName(room.t, room) }, - }), [room, rid]); + const context = useMemo(() => { + if (!room) { + return null; + } + room._id = rid; + return { + rid, + room: { ...room, name: roomTypes.getRoomName(room.t, room) }, + }; + }, [room, rid]); if (!room) { return <>; diff --git a/client/views/room/providers/ToolboxProvider.tsx b/client/views/room/providers/ToolboxProvider.tsx index 6380a3168d822..bc6a790e683cb 100644 --- a/client/views/room/providers/ToolboxProvider.tsx +++ b/client/views/room/providers/ToolboxProvider.tsx @@ -1,5 +1,5 @@ import React, { ReactNode, useContext, useMemo, useState, useCallback, useLayoutEffect } from 'react'; -import { useDebouncedState, useMutableCallback } from '@rocket.chat/fuselage-hooks'; +import { useDebouncedState, useMutableCallback, useSafely } from '@rocket.chat/fuselage-hooks'; import { Handler } from '@rocket.chat/emitter'; import { ToolboxContext } from '../lib/Toolbox/ToolboxContext'; @@ -56,7 +56,7 @@ export const ToolboxProvider = ({ children, room }: { children: ReactNode; room: const allowAnonymousRead = useSetting('Accounts_AllowAnonymousRead'); const uid = useUserId(); const [activeTabBar, setActiveTabBar] = useState<[ToolboxActionConfig|undefined, string?]>([undefined]); - const [list, setList] = useDebouncedState>(new Map(), 5); + const [list, setList] = useSafely(useDebouncedState>(new Map(), 5)); const handleChange = useMutableCallback((fn) => { fn(list); setList((list) => new Map(list)); }); const { listen, actions } = useToolboxActions(room);