Skip to content

Commit 206f70c

Browse files
committed
Fix async route page refresh
1 parent d56ff77 commit 206f70c

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/components/ConnectionRequired.tsx

+19-15
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,25 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
150150
useEffect(() => {
151151
// Check connection status on initial page load
152152
const apiClient = ServerConnections.currentApiClient();
153-
const firstConnection = ServerConnections.firstConnection;
154-
console.debug('[ConnectionRequired] connection state', firstConnection?.State);
155-
ServerConnections.firstConnection = null;
156-
157-
if (firstConnection && firstConnection.State !== ConnectionState.SignedIn && !apiClient?.isLoggedIn()) {
158-
handleIncompleteWizard(firstConnection)
159-
.catch(err => {
160-
console.error('[ConnectionRequired] could not start wizard', err);
161-
});
162-
} else {
163-
validateUserAccess()
164-
.catch(err => {
165-
console.error('[ConnectionRequired] could not validate user access', err);
166-
});
167-
}
153+
const connection = Promise.resolve(ServerConnections.firstConnection ? null : ServerConnections.connect());
154+
connection.then(firstConnection => {
155+
console.debug('[ConnectionRequired] connection state', firstConnection?.State);
156+
ServerConnections.firstConnection = true;
157+
158+
if (firstConnection && firstConnection.State !== ConnectionState.SignedIn && !apiClient?.isLoggedIn()) {
159+
handleIncompleteWizard(firstConnection)
160+
.catch(err => {
161+
console.error('[ConnectionRequired] could not start wizard', err);
162+
});
163+
} else {
164+
validateUserAccess()
165+
.catch(err => {
166+
console.error('[ConnectionRequired] could not validate user access', err);
167+
});
168+
}
169+
}).catch(err => {
170+
console.error('[ConnectionRequired] failed to connect', err);
171+
});
168172
}, [handleIncompleteWizard, validateUserAccess]);
169173

170174
if (isLoading) {

src/index.jsx

-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ build: ${__JF_BUILD_VERSION__}`);
110110
Events.on(apiClient, 'requestfail', appRouter.onRequestFail);
111111
});
112112

113-
// Connect to server
114-
ServerConnections.firstConnection = await ServerConnections.connect();
115-
116113
// Render the app
117114
await renderApp();
118115

0 commit comments

Comments
 (0)