Skip to content

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

Merged
merged 1 commit into from
Aug 19, 2019

Conversation

kamilogorek
Copy link
Contributor

Fixes #2202

@getsentry-bot
Copy link
Contributor

getsentry-bot commented Aug 14, 2019

Warnings
⚠️ Please add a changelog entry for your changes.
Messages
📖 ✅ TSLint passed
📖

@sentry/browser bundle gzip'ed minified size: (ES5: 16.1689 kB) (ES6: 15.3408 kB)

Generated by 🚫 dangerJS against 07d8341

@@ -911,6 +912,21 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() {
};
}

function popFrames(stacktrace: any, popSize: number): any {
if (typeof popSize !== 'number' || popSize === 0) {

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 :)

Copy link
Contributor Author

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 {
Copy link
Member

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?!

Suggested change
function popFrames(stacktrace: any, popSize: number): any {
function popFrames(stacktrace: any, popSize: number = 0): any {

Copy link
Contributor Author

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.

@HazAT
Copy link
Member

HazAT commented Aug 19, 2019

Ahh and changelog plz!

@kamilogorek kamilogorek merged commit 2979b2c into master Aug 19, 2019
@kamilogorek kamilogorek deleted the react-framestopop branch August 19, 2019 10:36
@@ -911,6 +912,21 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() {
};
}

function popFrames(stacktrace: any, popSize: number): any {
if (Number.isNaN(popSize)) {

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

Copy link
Contributor Author

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

Copy link

@jiananshi jiananshi Aug 20, 2019

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiananshi

image

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 😅

Copy link

@jiananshi jiananshi Aug 21, 2019

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

@kamilogorek kamilogorek Sep 16, 2019

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React's minified errors caught in errors boundary are not reported when whitelistUrls is set
4 participants