diff --git a/apps/meteor/client/lib/appLayout.tsx b/apps/meteor/client/lib/appLayout.tsx index 3962a0f300cb..bd632395ce48 100644 --- a/apps/meteor/client/lib/appLayout.tsx +++ b/apps/meteor/client/lib/appLayout.tsx @@ -4,7 +4,6 @@ import React, { lazy } from 'react'; const ConnectionStatusBar = lazy(() => import('../components/connectionStatus/ConnectionStatusBar')); const BannerRegion = lazy(() => import('../views/banners/BannerRegion')); -const PortalsWrapper = lazy(() => import('../views/root/PortalsWrapper')); const ModalRegion = lazy(() => import('../views/modal/ModalRegion')); const ActionManagerBusyState = lazy(() => import('../components/ActionManagerBusyState')); const CloudAnnouncementsRegion = lazy(() => import('../views/cloud/CloudAnnouncementsRegion')); @@ -35,7 +34,6 @@ class AppLayoutSubscription extends Emitter<{ update: void }> { {element} - ); diff --git a/apps/meteor/client/lib/portals/portalsSubscription.ts b/apps/meteor/client/lib/portals/portalsSubscription.ts deleted file mode 100644 index 513393eb983a..000000000000 --- a/apps/meteor/client/lib/portals/portalsSubscription.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Emitter } from '@rocket.chat/emitter'; -import { Random } from '@rocket.chat/random'; -import type { ReactPortal } from 'react'; - -type SubscribedPortal = { - portal: ReactPortal; - key: string; -}; - -type PortalsSubscription = { - subscribe: (callback: () => void) => () => void; - getSnapshot: () => SubscribedPortal[]; - has: (key: unknown) => boolean; - set: (key: unknown, portal: ReactPortal) => void; - delete: (key: unknown) => void; -}; - -const createPortalsSubscription = (): PortalsSubscription => { - const portalsMap = new Map(); - let portals = Array.from(portalsMap.values()); - const emitter = new Emitter<{ update: void }>(); - - return { - getSnapshot: (): SubscribedPortal[] => portals, - subscribe: (callback): (() => void) => emitter.on('update', callback), - delete: (key): void => { - portalsMap.delete(key); - portals = Array.from(portalsMap.values()); - emitter.emit('update'); - }, - set: (key, portal): void => { - portalsMap.set(key, { portal, key: Random.id() }); - portals = Array.from(portalsMap.values()); - emitter.emit('update'); - }, - has: (key): boolean => portalsMap.has(key), - }; -}; - -export const portalsSubscription = createPortalsSubscription(); - -export const unregisterPortal = (key: unknown): void => { - portalsSubscription.delete(key); -}; - -export const registerPortal = (key: unknown, portal: ReactPortal): (() => void) => { - portalsSubscription.set(key, portal); - return (): void => { - unregisterPortal(key); - }; -}; diff --git a/apps/meteor/client/views/root/PortalWrapper.ts b/apps/meteor/client/views/root/PortalWrapper.ts deleted file mode 100644 index b11724d9c1d1..000000000000 --- a/apps/meteor/client/views/root/PortalWrapper.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type { ReactElement, ReactNode } from 'react'; -import { PureComponent } from 'react'; - -type PortalWrapperProps = { - portal: ReactElement; -}; - -type PortalWrapperState = { - errored: boolean; -}; - -class PortalWrapper extends PureComponent { - state: PortalWrapperState = { errored: false }; - - static getDerivedStateFromError(): PortalWrapperState { - return { errored: true }; - } - - // eslint-disable-next-line @typescript-eslint/no-empty-function - componentDidCatch(): void {} - - render(): ReactNode { - if (this.state.errored) { - return null; - } - - return this.props.portal; - } -} - -export default PortalWrapper; diff --git a/apps/meteor/client/views/root/PortalsWrapper.tsx b/apps/meteor/client/views/root/PortalsWrapper.tsx deleted file mode 100644 index 2fafb11f9dac..000000000000 --- a/apps/meteor/client/views/root/PortalsWrapper.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; -import { useSyncExternalStore } from 'use-sync-external-store/shim'; - -import { portalsSubscription } from '../../lib/portals/portalsSubscription'; -import PortalWrapper from './PortalWrapper'; - -const PortalsWrapper = () => { - const portals = useSyncExternalStore(portalsSubscription.subscribe, portalsSubscription.getSnapshot); - - return ( - <> - {portals.map(({ key, portal }) => ( - - ))} - - ); -}; - -export default PortalsWrapper;