diff --git a/apps/meteor/client/lib/createRouteGroup.tsx b/apps/meteor/client/lib/createRouteGroup.tsx index 00bdf320b3f..8f8691f8296 100644 --- a/apps/meteor/client/lib/createRouteGroup.tsx +++ b/apps/meteor/client/lib/createRouteGroup.tsx @@ -48,6 +48,11 @@ const registerLazyComponentRoute = ( const handleExit = (context: Context): void => { computation?.stop(); + + if (!context.oldRoute) { + return; + } + if (context.route.group?.name === context.oldRoute?.group?.name) { return; } diff --git a/apps/meteor/ee/app/license/client/index.ts b/apps/meteor/ee/app/license/client/index.ts index 333c44c00c8..805b6b0ae22 100644 --- a/apps/meteor/ee/app/license/client/index.ts +++ b/apps/meteor/ee/app/license/client/index.ts @@ -1,22 +1,15 @@ import { fetchFeatures } from '../../../client/lib/fetchFeatures'; import { queryClient } from '../../../../client/lib/queryClient'; -const allModules = queryClient - .fetchQuery({ - queryKey: ['ee.features'], - queryFn: fetchFeatures, - }) - .then((features) => new Set(features)) - .catch((e) => { - console.error('Error getting modules', e); - return Promise.reject(e); - }); - export async function hasLicense(feature: string): Promise { try { - const features = await allModules; - return features.has(feature); + const features = await queryClient.fetchQuery({ + queryKey: ['ee.features'], + queryFn: fetchFeatures, + }); + return features.includes(feature); } catch (e) { + console.error('Error getting modules', e); return false; } } diff --git a/apps/meteor/ee/client/hooks/useHasLicenseModule.ts b/apps/meteor/ee/client/hooks/useHasLicenseModule.ts index 5c1ea7cab3b..a1492d39a01 100644 --- a/apps/meteor/ee/client/hooks/useHasLicenseModule.ts +++ b/apps/meteor/ee/client/hooks/useHasLicenseModule.ts @@ -1,19 +1,15 @@ -import { useState, useEffect } from 'react'; +import { useMethod, useUserId } from '@rocket.chat/ui-contexts'; +import { useQuery } from '@tanstack/react-query'; -import { hasLicense } from '../../app/license/client'; import type { BundleFeature } from '../../app/license/server/bundles'; export const useHasLicenseModule = (licenseName: BundleFeature): 'loading' | boolean => { - const [license, setLicense] = useState<'loading' | boolean>('loading'); + const method = useMethod('license:getModules'); + const uid = useUserId(); - useEffect(() => { - hasLicense(licenseName).then((enabled) => { - if (enabled) { - return setLicense(true); - } - setLicense(false); - }); - }, [licenseName]); + const features = useQuery(['ee.features'], method, { + enabled: !!uid, + }); - return license; + return features.data?.includes(licenseName) ?? 'loading'; };