Skip to content

Commit 8a6f493

Browse files
committed
Account for the config latency
1 parent 067a39b commit 8a6f493

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

frontend/apps/thunder-develop/src/AppWithConfig.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ import App from './App';
2727

2828
const queryClient: QueryClient = new QueryClient();
2929

30-
export default function AppWithConfig(): JSX.Element {
31-
const {getClientId, getServerUrl, getClientUrl, getScopes} = useConfig();
30+
export default function AppWithConfig(): JSX.Element | null {
31+
const {getClientId, getServerUrl, getClientUrl, getScopes, isLoading} = useConfig();
32+
33+
if (isLoading) {
34+
return null;
35+
}
3236

3337
return (
3438
<AsgardeoProvider

frontend/apps/thunder-gate/src/AppWithConfig.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ import {useConfig} from '@thunder/shared-contexts';
2222
import {BrandingProvider} from '@thunder/shared-branding';
2323
import AppWithTheme from './AppWithTheme';
2424

25-
export default function AppWithConfig(): JSX.Element {
26-
const {getServerUrl} = useConfig();
25+
export default function AppWithConfig(): JSX.Element | null {
26+
const {getServerUrl, isLoading} = useConfig();
27+
28+
if (isLoading) {
29+
return null;
30+
}
2731

2832
return (
2933
<AsgardeoProvider

frontend/packages/thunder-shared-contexts/src/Config/ConfigContext.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ export interface ConfigContextType {
7979
* @returns The client UUID string or undefined if not available
8080
*/
8181
getClientUuid: () => string | undefined;
82+
83+
/**
84+
* Indicates whether the configuration is still being loaded
85+
* @returns True if configuration is loading, false if ready
86+
*/
87+
isLoading: boolean;
8288
}
8389

8490
/**

frontend/packages/thunder-shared-contexts/src/Config/ConfigProvider.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* under the License.
1717
*/
1818

19-
import React, {useMemo, PropsWithChildren} from 'react';
19+
import {useMemo, useState, useEffect, PropsWithChildren} from 'react';
2020
import {ThunderConfig} from './types';
2121
import ConfigContext, {ConfigContextType} from './ConfigContext';
2222

@@ -81,11 +81,19 @@ function loadConfig(): ThunderConfig {
8181
* @public
8282
*/
8383
export default function ConfigProvider({children}: ConfigProviderProps) {
84+
const [isLoading, setIsLoading] = useState(true);
8485
const config = useMemo(() => loadConfig(), []);
8586

87+
useEffect(() => {
88+
if (config && typeof config === 'object' && config.server && config.client) {
89+
setIsLoading(false);
90+
}
91+
}, [config]);
92+
8693
const contextValue: ConfigContextType = useMemo(
8794
() => ({
8895
config,
96+
isLoading,
8997
getServerUrl: () => {
9098
// If public_url is provided, use it directly
9199
if (config.server.public_url) {
@@ -133,7 +141,7 @@ export default function ConfigProvider({children}: ConfigProviderProps) {
133141
return undefined;
134142
},
135143
}),
136-
[config],
144+
[config, isLoading],
137145
);
138146

139147
return <ConfigContext.Provider value={contextValue}>{children}</ConfigContext.Provider>;

0 commit comments

Comments
 (0)