Skip to content

Commit

Permalink
Fix dynamic import of atmosphere as top level await not allowed
Browse files Browse the repository at this point in the history
Env should be optional for other frameworks
Fixes #2867
  • Loading branch information
krissvaa committed Nov 13, 2024
1 parent 33b8cc7 commit 3ba43b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions packages/ts/frontend/src/FluxConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ type EndpointInfo = {
reconnect?(): ActionOnLostSubscription | void;
};

const initAtmosphere = async () => {
if (!import.meta.env.VITE_SW_CONTEXT) {
return await import('atmosphere.js').then((module) => module.default);
}
return undefined;
};
let atmosphere: Atmosphere.Atmosphere | undefined;

const atmosphere: Atmosphere.Atmosphere | undefined = await initAtmosphere();
(async () => {
if (!import.meta.env?.VITE_SW_CONTEXT) {
atmosphere = await import('atmosphere.js').then((module) => module.default);
}
})().catch((e) => {
console.error('Failed to load atmosphere.js', e);

Check warning on line 81 in packages/ts/frontend/src/FluxConnection.ts

View check run for this annotation

Codecov / codecov/patch

packages/ts/frontend/src/FluxConnection.ts#L81

Added line #L81 was not covered by tests
});

/**
* A representation of the underlying persistent network connection used for subscribing to Flux type endpoint methods.
Expand Down
2 changes: 1 addition & 1 deletion packages/ts/frontend/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ interface ImportMetaEnv {
}

interface ImportMeta {
readonly env: ImportMetaEnv;
readonly env?: ImportMetaEnv;
}

0 comments on commit 3ba43b0

Please sign in to comment.