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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/browser/src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
_namespace,
_publicKey,
_sdkBundleUrl,
_config
_config,
_lazy
) {
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!

if (document.scripts[i].src.indexOf(_publicKey) > -1) {
lazy = !(document.scripts[i].getAttribute('data-lazy') === 'no');
// If lazy was set to true above, we need to check if the user has set data-lazy="no"
// to confirm that we should lazy load the CDN bundle
if (lazy && document.scripts[i].getAttribute('data-lazy') === 'no') {
lazy = false;
}
break;
}
}
Expand Down Expand Up @@ -217,4 +222,4 @@
}
})(window, document, 'script', 'onerror', 'onunhandledrejection', 'Sentry', 'loader.js', '../../build/bundles/bundle.js', {
dsn: 'https://public@example.com/1'
});
}, true);