fix shelf-first visibleStartingIndex for empty content#32
Conversation
|
@stefanpenner Please help resolve the tests. |
|
@rwjblue / @stefanpenner Could anyone have a look on this ? |
7395a2f to
9b4fda6
Compare
| }); | ||
| }); | ||
|
|
||
| var contentC = [ |
There was a problem hiding this comment.
This appears to pass even if the fix is removed.
Without a reproduction of the problem, I don't really understand the fix here
There was a problem hiding this comment.
@stefanpenner The issue was that at line 228, we divide by index, which is content.length. If suppose the content array is cleared, the subsequent calculations are affected, leading to entry being undefined and causing the #26
This was reproduced in the test.
However, right now, after rebasing, I am getting stuck at an infinite loop at 246.
But the fix is to avoid the NaN.
There was a problem hiding this comment.
@mukilane in this scenario would it make sense to short-circuit the function, and return the expected visibleStartingIndex?
It doesn't seem like we need to loop anything if the list is empty, or the height is 0.
I haven't tested this yet, but it seems like:
if (height === 0 || length === 0) {
return 0;
}WDYT?
There was a problem hiding this comment.
@stefanpenner I wonder if a non-empty list would return a height 0.
Given that if length is 0, height would also be 0, so checking length would be fine, unless there is an odd case where entry's height is set to 0. 🤔
However, adding the height condition is fine with me, just in case.
Fixes: #26