-
Notifications
You must be signed in to change notification settings - Fork 289
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
Do not crash when unsetting scrollToRow #62
Conversation
@@ -912,7 +912,7 @@ var FixedDataTable = React.createClass({ | |||
} | |||
|
|||
var lastScrollToRow = oldState ? oldState.scrollToRow : undefined; | |||
if (props.scrollToRow !== lastScrollToRow) { | |||
if (typeof props.scrollToRow !== 'undefined' && props.scrollToRow !== null && props.scrollToRow !== lastScrollToRow) { |
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.
Maybe we should introduce lodash into our lib and use _.isNil instead?
We wouldn't need to worry about bloat if we implemented tree shaking.
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.
That would be cool, but I guess I would argue that could be a separate PR after this one (if this is accepted).
@@ -912,7 +912,7 @@ var FixedDataTable = React.createClass({ | |||
} | |||
|
|||
var lastScrollToRow = oldState ? oldState.scrollToRow : undefined; | |||
if (props.scrollToRow !== lastScrollToRow) { | |||
if (typeof props.scrollToRow !== 'undefined' && props.scrollToRow !== null && props.scrollToRow !== lastScrollToRow) { |
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.
I think we need to implement something similar for the other: scrollTop, scrollToRow and scrollToColumn
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.
I thought so too, but they weren't failing similar tests, while this one was, so I opted not to.
@@ -0,0 +1,28 @@ | |||
'use strict' | |||
|
|||
var jsdom = require('jsdom') |
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.
nit: missing semicolons throughout this file
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.
That's what I get for copying it from somewhere else. Sure would be nice to have ESLint set up for this project. Any interest in a PR doing so?
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.
Yeah, would love it!
What will it take to get this merged? Add semicolons? Would you like checks around |
@IanVS Just want to checkout the branch and test a couple edge cases. Are you in a hurry to get this merged in? |
Nope, no particular hurry, just want to make sure I understand the expectations. Wasn't sure if you were done reviewing. |
Added some extra tests; found scrollTop was also failing. @wcjordan Can you give my changes a look? |
@@ -920,7 +920,7 @@ var FixedDataTable = React.createClass({ | |||
} | |||
|
|||
var lastScrollTop = oldState ? oldState.scrollTop : undefined; | |||
if (props.scrollTop !== lastScrollTop) { | |||
if (typeof props.scrollTop !== 'undefined' && props.scrollTop !== null && props.scrollTop !== lastScrollTop) { |
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.
why use typeof for this check? why not just props.scrollTop !== undefined?
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.
Not sure, I just copied it. I think we can just do props.scrollTop != null since undefined == null
Will update this and above
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 a habit I suppose, but it's usually considered safer. In strict mode accessing a variable that is undefined will throw a referenceError. That may not apply in this case, but as a general rule to be safe that's how I like to check for undefined variables.
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.
Hmm that isn't my finding here: http://jsfiddle.net/s14sav6k/4/
But I'm not too familiar with strict mode. Do you have documentation which describes what can cause the ReferenceErrors? Could it be a browser specific implementation?
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.
I hate pointing to SO as a source of truth, but here's this: http://stackoverflow.com/questions/2703102/typeof-undefined-vs-null
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.
You'll get that error for variable reference, but not for property reference.
e.g. props.foo won't throw that error, as long as props is defined
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.
Cool, I think the case you're referring to is specific to references on the execution context (props for this case), rather than accessed on an object through dot notation (e.g. props.scrollTop).
If there's a risk of props not existing, we'd need to also add a typeof props !== undefined &&
check to avoid an error from the dot access. If not, I think we're safe with the short hand Kam suggests in both strict and non-strict modes.
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.
As I said, just a habit. ;)
* @return {!Object} | ||
*/ | ||
getTableState() { | ||
return this.refs['table'].state; |
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.
what's the motivation for this state access indirection? might be worth adding a comment.
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.
We use it to inspect the inner state for the tests. I'll update the annotation to further clarify
I added a few questions, but lgtm |
Thanks everyone. |
Published in 0.7.6 |
Description
This avoids trying to scroll to an
undefined
row.Motivation and Context
Since the latest release (0.7.5), I began to see the following error:
I found that this happened after setting a
scrollToRow
prop and then returning it toundefined
.How Has This Been Tested?
I tested this in my app, as well as added a test for it. Note: I needed to be able to
setState
, which required full rendering, so I add jsdom and react-dom to the dev dependencies.Screenshots (if appropriate):
Types of changes
Checklist: