-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Use framesToPop for InvaliantViolations in React errors #2204
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
9c2f513
to
07d8341
Compare
packages/browser/src/tracekit.ts
Outdated
@@ -911,6 +912,21 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() { | |||
}; | |||
} | |||
|
|||
function popFrames(stacktrace: any, popSize: number): any { | |||
if (typeof popSize !== 'number' || popSize === 0) { |
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.
My personal habit is using isNaN
to detect number in JavaScript since typeof NaN
also returns number
, feel free if it's over-defend :)
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.
Good catch. Will change that, thanks! :)
@@ -911,6 +912,21 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() { | |||
}; | |||
} | |||
|
|||
function popFrames(stacktrace: any, popSize: number): any { |
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.
Is there a reason not to use default value, then you could remove the number type check?!
function popFrames(stacktrace: any, popSize: number): any { | |
function popFrames(stacktrace: any, popSize: number = 0): any { |
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.
It's Tracekit, so we have to be very defensive in here. It's guarding us in case React breaks something, or someone decides to put framesToPop
property on their error objects.
Ahh and changelog plz! |
07d8341
to
dbdfa83
Compare
@@ -911,6 +912,21 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() { | |||
}; | |||
} | |||
|
|||
function popFrames(stacktrace: any, popSize: number): any { | |||
if (Number.isNaN(popSize)) { |
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.
Number.isNaN
is totally different than isNaN
, since Number.isNaN
detects if it's NaN
or not, isNaN
detects if it is Not A Number
, you should also check value 0
as your previous logic: if (isNaN(popSize) || popSize === 0)
Number.isNaN('sentry'); // false
isNaN('sentry'); // true
BTW, Number.isNaN
seems not work so good on IE browsers, haven't checked yet. Would be nice if I can get some information abt it from yours XD
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.
@jiananshi I know how they work, thanks for pointing that out anyway :)
I can skip 0
logic, as slice(0)
returns the same array, thus passing popSize === 0
will be effectively no-op.
Yes, Number.isNaN
is not IE friendly, but we already use it in our codebase. It's mentioned here https://docs.sentry.io/platforms/javascript/#browser-table
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.
Fine, let's take a step back and compare with the previous code:
// previous
if (typeof popSize !== 'number' || popSize === 0)
// current
if (Number.isNaN(popSize))
In the previous logic you do want a NUMBER but currently anythings besides NaN
is acceptable, not sure if that's what you want.
btw the browser-table is a nice design, just learned that.
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.
Thankfully it will work just fine anyway, as slice
can accept anything and it'll disregard anything other than a number. Thus this check is completely redundant anyway. Will remove it in the next patch release. Thanks and excuse my stubbornness 😅
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.
It's ok, as english is not my mother language previous comment may feel little bit annoying, if it is, pls don't mind.
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.
It's totally fine, my bad :)
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.
Will remove it in the next patch release.
Removed (will be commited soon) :)
Thanks again!
Fixes #2202