Skip to content

feat: Use framesToPop for InvaliantViolations in React errors - #2204

Merged
kamilogorek merged 1 commit into
masterfrom
react-framestopop
Aug 19, 2019
Merged

kamilogorek merged 1 commit into
masterfrom
react-framestopop

Conversation

@kamilogorek

Copy link
Copy Markdown
Contributor

Fixes #2202

@getsentry-bot

getsentry-bot commented Aug 14, 2019 •

Copy link
Copy Markdown
Contributor
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

Comment thread packages/browser/src/tracekit.ts Outdated
}

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

Copy link
Copy Markdown

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
Copy Markdown
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! :)

};
}

function popFrames(stacktrace: any, popSize: number): any {

Copy link
Copy Markdown
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
Copy Markdown
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

HazAT commented Aug 19, 2019

Copy link
Copy Markdown
Member

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
}

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

Copy link
Copy Markdown

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
Copy Markdown
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

@jiananshi jiananshi Aug 20, 2019 •

Copy link
Copy Markdown

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
Copy Markdown
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 😅

@jiananshi jiananshi Aug 21, 2019 •

Copy link
Copy Markdown

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

@kamilogorek kamilogorek Sep 16, 2019 •

Copy link
Copy Markdown
Contributor Author

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