-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
equals should skip null and undefined nodes fix #151 #192
Conversation
@smacker this looks great as far as i can tell. I get really nervous changing this algorithm though. I'd like to add some more assertions / variations of tests before merging this in to hedge against having a regression. Thanks for taking a stab at this! |
@lelandrichardson what tests would you like to add? Current tests suite of nodeEqual looks solid for me. |
@smacker Apologies for the delay. I want to get this change in, but just want to make sure it's not a regression before we merge. The test coverage right now is good but these equality metrics have a tendency to produce strange corner cases. I'm going to pull this branch down when I get a chance and play around with adding some tests. Thanks again for putting up a PR! |
This test still fail in master branch: it('should skip null children', () => {
expect(nodeEqual(
<div>{null}</div>,
<div></div>
)).to.equal(true);
}); It makes me sad :( |
@smacker you're absolutely right. It's my fault - i'm sorry. I want to get this change in I just wanted to test it more thoroughly first in fear of it causing an unwanted regression. I will pull this branch down tonight and test it out. Thanks for your patience. |
@smacker I've looked over this a bit and there are some corner cases where this algorithm isn't quite doing what it's supposed to. The problem is that once we are hitting the This can be demonstrated with the following (somewhat contrived) example:
Even though the In practice, Fixing this by only returning false if the children are not equal, and continuing iteration if they are, is the right way to solve this. In this case though, we run into a separate issue where an object that doesn't define children is not equal to one that does, but children is a non-renderable value (like What I came up with was this:
Please feel free to change your PR to use this tweaked algorithm, and I will be happy to accept it and to merge it in. I'll go ahead and do it myself if I don't hear back from you in a couple of days, but I wanted to give you an opportunity to update it since you've done the bulk of the work and have been waiting patiently for me to review it. |
Yes, I relied on react behavior. And it's not correct. Consider this example: expect(nodeEqual(
<div></div>,
<div>child</div>
)).to.equal(true); I added tests for all cases and fixed algorithm. |
rebased again... @lelandrichardson |
Looks good. Thanks for updating the logic, and for your patience! |
LGTM |
#151