-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(replay): Only call scope.getLastBreadcrumb
if available
#6969
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
@@ -26,6 +26,10 @@ export const handleScopeListener: (replay: ReplayContainer) => (scope: Scope) => | |||
* An event handler to handle scope changes. | |||
*/ | |||
export function handleScope(scope: Scope): Breadcrumb | null { | |||
if (typeof scope.getLastBreadcrumb !== 'function') { |
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.
LGTM. 👍🏼
I wish i would have created this PR before 🤦🏼 🥼
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.
According to this methods signature, scope
is always defined; so no need to guard against it being undefined ;)
Furthermore, this is where we call the function that ends up calling handleScope
. As you can see, it is guarded by the scope being defined there:
scope.addScopeListener(handleScopeListener(replay)); |
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.
awesome sauce... 🆒 . The guarded scope looks good ⚡
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.
l: I would just do if (scope.getLastBreadcrumb)
, saves some bytes and should be good enough here!
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.
size-limit report 📦
|
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.
👍 LGTM! For reference, let's do this fix, with the conscious decision that if such things keep popping up, we'll not commit to work around all of them. 🚀
Scope.getLastBreadcrumb
was introduced quite recently for replay and it generally works fine. Just in the few edge cases, where the base SDK version can't be changed or multiple hubs cause conflicts, Replay will crash when the method is not available on the passed scope. This PR letshandleScope
early-returnnull
in case thegetLastBreadcrumb
method does not exist. This will lead to missing breadcrumbs in the replay but at least it will avoid a crash.closes #6542