From 206f70cf34be16f3c266dcdf099bea7a3848d70c Mon Sep 17 00:00:00 2001 From: viown <48097677+viown@users.noreply.github.com> Date: Sun, 15 Dec 2024 14:01:12 +0300 Subject: [PATCH] Fix async route page refresh --- src/components/ConnectionRequired.tsx | 32 +++++++++++++++------------ src/index.jsx | 3 --- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/components/ConnectionRequired.tsx b/src/components/ConnectionRequired.tsx index 41b96cb360..198149ad3c 100644 --- a/src/components/ConnectionRequired.tsx +++ b/src/components/ConnectionRequired.tsx @@ -150,21 +150,25 @@ const ConnectionRequired: FunctionComponent = ({ useEffect(() => { // Check connection status on initial page load const apiClient = ServerConnections.currentApiClient(); - const firstConnection = ServerConnections.firstConnection; - console.debug('[ConnectionRequired] connection state', firstConnection?.State); - ServerConnections.firstConnection = null; + const connection = Promise.resolve(ServerConnections.firstConnection ? null : ServerConnections.connect()); + connection.then(firstConnection => { + console.debug('[ConnectionRequired] connection state', firstConnection?.State); + ServerConnections.firstConnection = true; - if (firstConnection && firstConnection.State !== ConnectionState.SignedIn && !apiClient?.isLoggedIn()) { - handleIncompleteWizard(firstConnection) - .catch(err => { - console.error('[ConnectionRequired] could not start wizard', err); - }); - } else { - validateUserAccess() - .catch(err => { - console.error('[ConnectionRequired] could not validate user access', err); - }); - } + if (firstConnection && firstConnection.State !== ConnectionState.SignedIn && !apiClient?.isLoggedIn()) { + handleIncompleteWizard(firstConnection) + .catch(err => { + console.error('[ConnectionRequired] could not start wizard', err); + }); + } else { + validateUserAccess() + .catch(err => { + console.error('[ConnectionRequired] could not validate user access', err); + }); + } + }).catch(err => { + console.error('[ConnectionRequired] failed to connect', err); + }); }, [handleIncompleteWizard, validateUserAccess]); if (isLoading) { diff --git a/src/index.jsx b/src/index.jsx index 1db2bcebef..8c151a6017 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -110,9 +110,6 @@ build: ${__JF_BUILD_VERSION__}`); Events.on(apiClient, 'requestfail', appRouter.onRequestFail); }); - // Connect to server - ServerConnections.firstConnection = await ServerConnections.connect(); - // Render the app await renderApp();