Skip to content

Commit 3ba43b0

Browse files
committed
Fix dynamic import of atmosphere as top level await not allowed
Env should be optional for other frameworks Fixes #2867
1 parent 33b8cc7 commit 3ba43b0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

packages/ts/frontend/src/FluxConnection.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ type EndpointInfo = {
7171
reconnect?(): ActionOnLostSubscription | void;
7272
};
7373

74-
const initAtmosphere = async () => {
75-
if (!import.meta.env.VITE_SW_CONTEXT) {
76-
return await import('atmosphere.js').then((module) => module.default);
77-
}
78-
return undefined;
79-
};
74+
let atmosphere: Atmosphere.Atmosphere | undefined;
8075

81-
const atmosphere: Atmosphere.Atmosphere | undefined = await initAtmosphere();
76+
(async () => {
77+
if (!import.meta.env?.VITE_SW_CONTEXT) {
78+
atmosphere = await import('atmosphere.js').then((module) => module.default);
79+
}
80+
})().catch((e) => {
81+
console.error('Failed to load atmosphere.js', e);
82+
});
8283

8384
/**
8485
* A representation of the underlying persistent network connection used for subscribing to Flux type endpoint methods.

packages/ts/frontend/src/vite-env.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ interface ImportMetaEnv {
66
}
77

88
interface ImportMeta {
9-
readonly env: ImportMetaEnv;
9+
readonly env?: ImportMetaEnv;
1010
}

0 commit comments

Comments
 (0)