-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allow dynamically import atmosphere.js for SW context #2901
base: fix/sw-context-access
Are you sure you want to change the base?
Conversation
f5f6170
to
cf3a028
Compare
5c613c4
to
33b8cc7
Compare
Env should be optional for other frameworks Fixes #2867
Quality Gate passedIssues Measures |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## fix/sw-context-access #2901 +/- ##
=========================================================
- Coverage 92.54% 92.52% -0.03%
=========================================================
Files 83 83
Lines 2832 2836 +4
Branches 732 733 +1
=========================================================
+ Hits 2621 2624 +3
- Misses 156 157 +1
Partials 55 55
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -0,0 +1,10 @@ | |||
// / <reference types="vite/client" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// / <reference types="vite/client" /> | |
/// <reference types="vite/client" /> |
(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); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(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); | |
}); | |
if (!import.meta.env?.VITE_SW_CONTEXT) { | |
try { | |
atmosphere = await import('atmosphere.js').then((module) => module.default); | |
} catch (e: unknown) { | |
console.error('Failed to load atmosphere.js', e); | |
} | |
} |
I'd suggest using top-level await here. Is it possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we can probably check the presence of the document
in globalThis
here, instead of VITE_SW_CONTEXT
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
top-level await is not allowed according to our project configuration.
Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid top-level await for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that creates a possible race condition, and in some cases the FluxConnection
can possibly be created before the Atmosphere is loaded.
Fixes #2867