@@ -94,7 +94,7 @@ function connectingMessage({ server, project_ids }) {
94
94
}
95
95
96
96
const getNewNatsConn = reuseInFlight ( async ( { cache, user } ) => {
97
- const { account_id } = webapp_client ;
97
+ const account_id = await getAccountId ( ) ;
98
98
if ( ! account_id ) {
99
99
throw Error ( "you must be signed in before connecting to NATS" ) ;
100
100
}
@@ -119,12 +119,23 @@ const getNewNatsConn = reuseInFlight(async ({ cache, user }) => {
119
119
}
120
120
} ) ;
121
121
122
+ // This is a hack to get around circular import during initial page load.
123
+ // TODO: properly clean up the import order
124
+ async function getAccountId ( ) {
125
+ try {
126
+ return webapp_client . account_id ;
127
+ } catch {
128
+ await delay ( 1 ) ;
129
+ return webapp_client . account_id ;
130
+ }
131
+ }
132
+
122
133
let cachedConnection : CoCalcNatsConnection | null = null ;
123
134
export const connect = reuseInFlight ( async ( ) => {
124
135
if ( cachedConnection != null ) {
125
136
return cachedConnection ;
126
137
}
127
- const { account_id } = webapp_client ;
138
+ const account_id = await getAccountId ( ) ;
128
139
const cache = getPermissionsCache ( ) ;
129
140
const project_ids = cache . get ( ) ;
130
141
const user = { account_id, project_ids } ;
@@ -283,7 +294,7 @@ class CoCalcNatsConnection extends EventEmitter implements NatsConnection {
283
294
// nothing to do
284
295
return ;
285
296
}
286
- const { account_id } = webapp_client ;
297
+ const account_id = await getAccountId ( ) ;
287
298
if ( ! account_id ) {
288
299
throw Error ( "you must be signed in before connecting to NATS" ) ;
289
300
}
0 commit comments