Skip to content
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

feat(loader): Make lazy-loading configurable #7232

Merged
merged 3 commits into from Feb 24, 2023
Merged

Conversation

AbhiPrasad
Copy link
Member

ref getsentry/sentry#44225

As per the work in getsentry/sentry#44876, make lazy loading a injectable option.

See https://docs.sentry.io/platforms/javascript/install/lazy-load-sentry/#load-timing for more details on how this works.

@AbhiPrasad AbhiPrasad self-assigned this Feb 20, 2023
@AbhiPrasad AbhiPrasad requested review from a team, mydea and Lms24 and removed request for a team February 20, 2023 14:47
) {
var lazy = true;
var lazy = _lazy;
var forceLoad = false;

for (var i = 0; i < document.scripts.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, we still want this to be overwritable by the script tag here:

lazy = !(document.scripts[i].getAttribute('data-lazy') === 'no');

Or should we guard that to be basically:

var lazy = _lazy;

// if lazy is set to false, we cannot opt in?
if (lazy) {
  // check if option out of lazy
  for (...) {}
} 

Just thinking, because I guess it would kind of break in the case of performance/replay if this were to be overwritten to true again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, we still want this to be overwritable by the script tag here:

Yup, the script tag always supercedes this. Here are the scenarios:

  1. lazy = true + data-lazy not set -> lazy == true (default for errors)
  2. lazy = false + data-lazy not set -> lazy == false (default for replay + perf)
  3. lazy = true + data-lazy === 'no' -> lazy == false
  4. lazy = false + data-lazy === 'no -> lazy == false

Copy link
Member

@mydea mydea Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. lazy = false + data-lazy not set -> lazy == false (default for replay + perf)

but wouldn't this case, with the current code, lead to lazy == true? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right 🤦 - I misunderstood the boolean condition ahhhhh

Let me change this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with f09a965!

@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 20.11 KB (+0.22% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 62.49 KB (+0.31% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.74 KB (+0.28% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 55.5 KB (+0.35% 🔺)
@sentry/browser - Webpack (gzipped + minified) 20.48 KB (+0.35% 🔺)
@sentry/browser - Webpack (minified) 66.94 KB (+0.28% 🔺)
@sentry/react - Webpack (gzipped + minified) 20.51 KB (+0.33% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 48.05 KB (+0.41% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 27.04 KB (+0.38% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.29 KB (+0.35% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 42.78 KB (+0.4% 🔺)
@sentry/replay - Webpack (gzipped + minified) 36.83 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 60.34 KB (+0.17% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 53.91 KB (+0.12% 🔺)

@AbhiPrasad AbhiPrasad merged commit 87e919c into develop Feb 24, 2023
@AbhiPrasad AbhiPrasad deleted the abhi-loader-lazy-load branch February 24, 2023 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants