From d6dc308fd4011fbf14ee5aaa652cdff06e51a3dc Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Wed, 5 Jul 2023 21:43:46 +0800 Subject: [PATCH] fix(console): disable unnecessary fetchings when switching tenants (#4123) --- packages/console/src/contexts/TenantsProvider.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/console/src/contexts/TenantsProvider.tsx b/packages/console/src/contexts/TenantsProvider.tsx index 077bff954..e69192561 100644 --- a/packages/console/src/contexts/TenantsProvider.tsx +++ b/packages/console/src/contexts/TenantsProvider.tsx @@ -3,7 +3,6 @@ import { type TenantInfo, TenantTag } from '@logto/schemas/models'; import { conditionalArray, noop } from '@silverhand/essentials'; import type { ReactNode } from 'react'; import { useCallback, useMemo, createContext, useState } from 'react'; -import type { NavigateOptions } from 'react-router-dom'; import { isCloud } from '@/consts/env'; import { getUserTenantId } from '@/consts/tenants'; @@ -42,7 +41,7 @@ type Tenants = { currentTenantStatus: CurrentTenantStatus; setCurrentTenantStatus: (status: CurrentTenantStatus) => void; /** Navigate to the given tenant ID. */ - navigateTenant: (tenantId: string, options?: NavigateOptions) => void; + navigateTenant: (tenantId: string) => void; }; const { tenantId, indicator } = defaultManagementApi.resource; @@ -95,8 +94,11 @@ function TenantsProvider({ children }: Props) { // Use `window.open()` to force page reload since we use `basename` for the router // which will not re-create the router instance when the URL changes. window.open(`/${tenantId}`, '_self'); - setCurrentTenantId(tenantId); setCurrentTenantStatus('pending'); + // Temporarily disable the current tenant ID change since it will cause some providers + // to re-initialize and re-fetch the data, which is unexpected for now. + // This will be fixed once we merge all routers into one. + // setCurrentTenantId(tenantId); }, []); const currentTenant = useMemo(