-
Notifications
You must be signed in to change notification settings - Fork 31
.ready: fix behavior when packages fail to load #63
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
base: master
Are you sure you want to change the base?
Conversation
Netto brought an error with the Appcues integration up to my attention. Apparently when the script fails to load, it causes an exception which bubbles up to the top. I looked through the code and was pretty surprised by this, since the Appcues integration itself is very few lines of code, and nothing out of the ordinary. When I dug in, I realized that this comes from an error where the Appcues javascript fails to load for some reason. When that happens here's the sequence of events: - segmentio/load-script gets called, and then calls a callback with the error - this in turn calls .ready (in Appcues, but I think also many other integrations) - this emits a ready handler, which then immediately starts flushing the message queue, causing an uncaught exception This fix instead causes .ready when called with an error to _not_ mark the integration as ready. Avoiding further errors. The one thing I'm unsure of here is whether we ever end up calling .ready() with an argument–my hunch is 'no' given that it wouldn't do anything, but it might be worth adding an instanceof Error check. Thoughts?
cc @nettofarah this should fix the uncaughts we're seeing |
Separately, we should probably think about a way to make sure that this is try-catched in each integration, if it somehow errors in the callback and set of queues. |
One thing I notice is that https://github.com/segmentio/analytics.js-core/blob/master/test/analytics.test.js seems to use the only variety of .ready(callback). I can't tell for sure what it intends and this might just be legacy behavior. It don't see any production cases of calling .ready with any arguments, so we should be safe in that regard, though I agree that adding in a simple |
Nice - I think the reasoning sound good to me. Couple of notes:
|
Thanks for the reviews guys! I hadn't realized either the 2.x branch or the .ready problem... I'll circle back here. One idea for the short-term is to update the Appcues code to now fire when an error is encountered. I'm not sure if I'll have enough cycles on-hand to go through and audit everything right now, but let me think on it for another day. |
thanks for the update, @calvinfo. |
I've added this to our JIRA (https://segment.atlassian.net/browse/LIB-372) so we can pick this up soon. |
We're running into this issue now. An Ad-Blocker blocks twitter ads from loading, and then none of our integrations load. Is there anything we can do to move this fix forward? Once this part of it is merged we would want to update the twitter integration itself to propagate errors back to analytics.js |
Netto brought an error with the Appcues integration up to my
attention. Apparently when the script fails to load, it causes
an exception which bubbles up to the top.
I looked through the code and was pretty surprised by this, since
the Appcues integration itself is very few lines of code, and
nothing out of the ordinary.
When I dug in, I realized that this comes from an error where the
Appcues javascript fails to load for some reason.
When that happens here's the sequence of events:
with the error
other integrations)
flushing the message queue, causing an uncaught exception
This fix instead causes .ready when called with an error to
not mark the integration as ready. Avoiding further errors.
The one thing I'm unsure of here is whether we ever end up calling
.ready() with an argument–my hunch is 'no' given that it wouldn't
do anything, but it might be worth adding an instanceof Error check.
Thoughts?
Relevant Appcues code: https://github.com/segment-integrations/analytics.js-integration-appcues/blob/master/lib/index.js#L27-L29
Relevant a.js integration load code: https://github.com/segmentio/analytics.js-integration/blob/master/lib/protos.js#L237-L280