From 4f05bcbd52b6dd37571e92e768d28a90ac1951e1 Mon Sep 17 00:00:00 2001 From: Nadav Shatz Date: Thu, 19 Dec 2024 15:23:28 +0200 Subject: [PATCH] fix(react-bindings): multiple client async start handling while loading --- .../src/useStatsigInternalClientFactoryAsync.ts | 4 ++++ samples/react/src/main.tsx | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/react-bindings/src/useStatsigInternalClientFactoryAsync.ts b/packages/react-bindings/src/useStatsigInternalClientFactoryAsync.ts index 72d95505..5af0d8b1 100644 --- a/packages/react-bindings/src/useStatsigInternalClientFactoryAsync.ts +++ b/packages/react-bindings/src/useStatsigInternalClientFactoryAsync.ts @@ -18,6 +18,10 @@ export function useStatsigInternalClientFactoryAsync( const client = useMemo(() => { if (clientRef.current) { + Promise.resolve(clientRef.current) + .catch(Log.error) + .finally(() => setIsLoading(false)); + return clientRef.current; } diff --git a/samples/react/src/main.tsx b/samples/react/src/main.tsx index e9d38353..19ab0705 100644 --- a/samples/react/src/main.tsx +++ b/samples/react/src/main.tsx @@ -3,7 +3,7 @@ import '@fontsource/roboto/400.css'; import '@fontsource/roboto/500.css'; import '@fontsource/roboto/700.css'; import { Box } from '@mui/material'; -import { ReactNode, lazy } from 'react'; +import { ReactNode, StrictMode, lazy } from 'react'; import * as ReactDOM from 'react-dom/client'; import { RouteObject, @@ -89,4 +89,8 @@ function App() { ); } -root.render(); +root.render( + + + , +);