-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lazy Loading Integrations #10905
Comments
Can we not just use |
The problem with this is mainly that the fact if this works depends on the users of the SDK having a bundler that supports |
The only bundler I can remember thats lacking here is esbuild and even then, worse case it seems to inline the import so you'd just lose the laziness. There might be some others though! Or as you suggest, a non-lazy version as a backup?
In the browser, import and async import both just use URLs, whether they are relative or absolute they're still just all URLs. The only caveat is that the JavaScript files must be served with the correct mime type and cors headers if it's cross origin. Import maps just allow developers to replace the URLs with some string names. For example Sentry could publish bare browser ESM files that can be used like this in any modern browser: <script type="module">
import { init } from 'https://browser.sentry-cdn.com/7.105.0/esm.js';
init({ dsn: '__DSN__' });
const integration = await import('https://browser.sentry-cdn.com/7.105.0/some-integration.js');
</script> |
This can be used to lazy load a pluggable integration. Usage: ```js async function getOrLazyLoadFeedback() { const existing = Sentry.getFeedback(); // check if it has already been installed if (existing) { return existing; } try { const feedbackIntegration = await Sentry.lazyLoadIntegration('feedbackIntegration'); client.addIntegration(feedbackIntegration()); } catch(error) { // this can error, we need to handle this! } } ``` Closes #10905
This can be used to lazy load a pluggable integration. Usage: ```js async function getOrLazyLoadFeedback() { const existing = Sentry.getFeedback(); // check if it has already been installed if (existing) { return existing; } try { const feedbackIntegration = await Sentry.lazyLoadIntegration('feedbackIntegration'); client.addIntegration(feedbackIntegration()); } catch(error) { // this can error, we need to handle this! } } ``` Closes getsentry#10905
This is especially a requirement for feedback & screenshot capturing, but ideally we can build this in a generic way so also others things (e.g. the Loader) can leverage it.
For feedback, we want to allow users to capture & annotate screenshots. This is quite some code, so we want to lazy load this. However, it is not super easy today to set up lazy loading, and it requires bundler-specifics to work properly.
This proposes to provide an easy to use solution for this:
client.lazyAddIntegration(integrationName)
.This API could be used like this:
Which would under the hood do something like this:
This leverages the fact that we can already publish integrations as CDN bundles, which are versioned through the URL. This way, we can easily load the correct version of an integration for the current version.
The additional benefit of this is that it fully interops with non-lazy loading. E.g. if you don't want this, you can just do
addIntegration()
normally - nothing needs to be done! This also means that testing this is easy, and users who may not want to load from a CDN can justawait import()
themselves as before.The text was updated successfully, but these errors were encountered: