-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(loader): Improve loader callback handling #58070
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
Conversation
|
🚨 Warning: This pull request contains Frontend and Backend changes! It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently. Have questions? Please ask in the |
lforst
left a comment
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.
I have a slight feeling that we're only contributing to the confusingness of this file with this change. Ideally, we should defer the calling of init until the script tag's load event handler fired no? I won't block this though.
Codecov Report
@@ Coverage Diff @@
## master #58070 +/- ##
==========================================
- Coverage 79.11% 79.10% -0.02%
==========================================
Files 5144 5143 -1
Lines 224118 224107 -11
Branches 37741 37740 -1
==========================================
- Hits 177305 177273 -32
- Misses 41136 41154 +18
- Partials 5677 5680 +3
|
I do not disagree, however it is sadly a bit opaque when the |
e7cf355 to
bd00b4d
Compare
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.
I extracted all of this into a function & adjusted it so that we only call setupSDK in the next tick, which hopefully makes all of this a bit clearer!
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.
Adding once and passive here which IMHO make sense (the handler can be cleaned up after being called), and in older browsers will just be ignored.
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.
Renaming this to be a bit clearer, naming wise.
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.
I think we can get rid of this. Instead, when a user call Sentry.forceLoad(), we simply inject the SDK the same way we would for a non-lazy setup - all the other logic is not needed IMHO?
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.
Problem: Inbetween removing these and waiting for the next tick there might be an error which is not recorded. We need to remove these listeners right before we attach the actual non-buffered once, so in theory right before the call to the actual Sentry.init.
As discussed: Let's move it into the monkeypatch init.
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.
moved this!
15ebbab to
1052202
Compare
|
@lforst updated this according to what we talked about! |
1052202 to
17a1f7d
Compare
This updates the loader based on this PR: getsentry/sentry#58070 and also actually fixes/improves the loader tests by avoiding importing `@sentry/browser`. This is not needed and actually obfuscates the "real"/"normal" behavior (just look at the generated `dist` folder for a test. Instead, I added an eslint rule to allow `Sentry` as a global for these cases, and just access them directly. This also uncovered an incorrect test, which I adjusted so it works. I also added a new test to ensure custom config works.
This slightly refactors the loader script to hopefully fix getsentry/sentry-javascript#9216.
onLoadCallbacksaround, which is unnecessary since we are actually using the same instance everywhere that we mutate, so we can just access the variable directly.onLoadhandler was registered. I suspect this may be due to caching behavior whereaddEventListener('load')may fire immediately (??) - I could replicate it sometimes, sometimes not, when refreshing the page repeatedly. Anyhow, since we rely on this firing after a user had the chance to callSentry.onLoad, I think it at least doesn't hurt to call this in the next event tick, to potentially fix racing conditions there.