-
Notifications
You must be signed in to change notification settings - Fork 290
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
Fetch and Cache previous row heights #701
Conversation
Hi thanks for the PR. We also need to add unit tests to make sure the scroll offsets are calculated precisely, and that rows are actually cached and not re-fetched. |
src/reducers/index.js
Outdated
@@ -209,6 +212,18 @@ const slice = createSlice({ | |||
state.scrolling = true; | |||
state.scrollX = scrollX; | |||
}, | |||
updateRowHeights(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.
how about we pass an optional parameter updatedRowIndex, this way we wont need to set rowUntilOffsetsAreExact as 0 everytime.
For eg lets say there are 10000 rows and we have updated the height of 5000th row in that case we dont need to invalidate row heights and offsets of rows before 5000th row and we can simply set
state.getInternal().rowUntilOffsetsAreExact = updatedRowIndex //optional param
and if this param is not passed then we can set it to 0
Furthermore if the current rowUntilOffsetsAreExact is less than the updatedRowIndex we dont need to change state (rowUntilOffsetsAreExact)
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 is ok. I have added this parameter
…ights when scrolling to a y position
…ights when scrolling to a y position
I have added two tests for the two cases mentioned above |
Please let us know if this new version it is ok and can be accepted. |
docs/public_api/api_reference.md
Outdated
starting with the ```firstUpdatedRowIndex``` | ||
If the method is called without passing the ```firstUpdatedRowIndex``` it updates all the row heights | ||
```ts | ||
function() |
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: function(firstUpdatedRowIndex: number)
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.
Ok. Thank you. I have added this parameter
Thanks a lot for the changes, these look good just had a minor change suggestion and we also really appreciate you for adding the test |
Hey, sorry for the delay. @karry08 did some rounds of testing against various scenarios, and now we're of the opinion of feature flagging the changes:
@daniela-mateescu , @karry08 , we should probably bring a prop to control the new behavior. |
on scrollTo() compute all the row height that were not computed before if isScrollTopExact
Hi! Thanks for your testing. I made this change, and now the scroll bar jump works ok. Please let me know if you think that this solution is ok and can be accepted |
Hi guys. Any news? Thanks! |
.getInternal() | ||
.rowOffsetIntervalTree.sumUntil(state.firstRowIndex) - | ||
state.firstRowOffset; | ||
const scrollAnchor = scrollTo(state, currentScrollY); |
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.
shouldn't this pass the third param as props.useExactRowHeight
or true
?
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.
Yes. You are right. I have changed this. Thank you
Sorry for the lack of updates last week. @karry08 is investigating on a trick that allows us to fetch just the previous rows but still keep the scroll bar in sync with the cursor. As for the new changes in this PR, I see that the latest commit makes FDT fetch ALL rows at once. Using the new changes as an example: We're still discussing internally about this. |
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.
LGTM with 1 suggestion!
And friendly ping on this for reviewers: @karry08 , @AmanGupta2708 , please see my previous comment.
If noone has concerns with the plan, I'll proceed with merging this.
src/FixedDataTable.js
Outdated
* By setting ```isScrollTopExact``` to true, when trying to scroll to ```scrollTop``` position, the table will consider | ||
* the exact row heights, so the offset of the displayed rows will be correct | ||
*/ | ||
isScrollTopExact: PropTypes.bool, |
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.
Let's rename this to isVerticalScrollExact
since it deals with vertical scrolls in general, and not exclusive to scrollTop
as before.
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.
isVerticalScrollExact
seems better to me. I changed and use this instead of` isScrollTopExact
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 was almost about to merge this, but then I realized the changes here no longer work as expected when controlled scrolling is OFF.
When I simply set isVerticalScrollExact
to true in the DynamicRowHeightsExample
, FDT does not fetch all row heights.
Apologies for finding this late :( .
@daniela-mateescu , could you take another took?
And thanks in advance for your patience. I'll take another look on priority once the new changes are pushed in.
Please let me know if anything is unclear/tricky to solve.
src/reducers/scrollAnchor.js
Outdated
@@ -68,12 +68,23 @@ export function getScrollAnchor(state, newProps, oldProps) { | |||
* changed: boolean, | |||
* }} | |||
*/ | |||
export function scrollTo(state, scrollY) { | |||
export function scrollTo(state, scrollY, isVerticalScrollExact) { |
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.
There are calls to this function in other parts of the codebase where the third param is unspecified.
Some examples (but not limited to):
fixed-data-table-2/src/reducers/index.js
Line 204 in 6bd7bb8
const scrollAnchor = scrollTo(state, scrollY); scrollActions.scrollToY(scrollPos); this.state.scrollToY(scrollPos);
This has the risk that some workflows in the table (eg: uncontrolled scrolling) don't use exact row offsets even when isVerticalScrollExact
is true.
There's two approaches that I can immediately think of:
The first one is of course pass the prop isVerticalScrollExact
in all these usages as the third param.
But this can be a bit cumbersome cause some of the calls are nested within components.
The second one -- which I'm more inclined towards -- is to simply copy the isVerticalScrollExact
prop to the redux store as part of "input" state (see setStateFromProps()
) for similar cases.
Once this is done, this reducer can simply query state.isVerticalScrollExact
, thus avoiding the need for the caller to pass it explicitly.
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.
Hello!
Thank you for this observation. I have modified as you suggested in order to avoid passing isVerticalScrollExact
but instead pass it via state. Now the row heights are computed also for the DynamicRowHeightExample
.
Do you think it's ok now?
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.
nice, that works.
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.
LGTM, thanks for the continously addressing the comments!
There's still an edge case where the initial scroll AND "jump to row" scroll actions don't use exact scroll offsets even with isVerticalScrollExact
set as true.
I think this is because the scrollTo
reducer doesn't get called in these scenarios.
You can reproduce this by simply checking out the DynamicRowHeights example, specifying isVerticalScrollExact={true}
, and scrolling exactly once by clicking on the vertical scrollbar area.
However, I think we can track and solve the edge case with a separate issue/PR, especially because the new changes are feature flagged via isVerticalScrollExact
.
I'm going ahead with merging the PR, but it would be nice to fix the edge case soon.
cc: @karry08
Released with v2.0.5. |
Fix for #700
Description
In case of variable row height, when scrolling to an exact Y position ensure that all the row heights before that Y position are exact. Avoid asking for the actual height for the ones asked before.
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: