-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
fix: prevent infinite rerendering of DataTable #18087
Conversation
export const useFetchMoreOnBottomReached = ({ | ||
tableContainerRef, | ||
hasNextPage, | ||
fetchNextPage, | ||
isFetching, | ||
}: { | ||
tableContainerRef: React.RefObject<HTMLDivElement>; | ||
hasNextPage: boolean; | ||
fetchNextPage: () => void; | ||
isFetching: boolean; | ||
}) => { | ||
const fetchMoreOnBottomReached = useCallback( | ||
(containerRefElement?: HTMLDivElement | null) => { | ||
if (containerRefElement) { | ||
const { scrollHeight, scrollTop, clientHeight } = containerRefElement; | ||
if (scrollHeight - scrollTop - clientHeight < 300 && !isFetching && totalFetched < totalDBRowCount) { | ||
if (scrollHeight - scrollTop - clientHeight < 300 && !isFetching && hasNextPage) { | ||
fetchNextPage(); | ||
} | ||
} | ||
}, | ||
[fetchNextPage, isFetching, totalFetched, totalDBRowCount] | ||
[fetchNextPage, isFetching] |
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 relied on totalFetched
and totalDBRowCount
. However, when filters are applied, we cannot.
For example, let's say the filter result is only a single row. Then it's like:
totalFetched === 1
totalDBRowCount === 23424 // whatever the total db row count
Then this if condition is true, so it tries to fetch the next page even though there is no next page at all. So from now on, we use hasNextPage
variable instead.
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (12/10/24)1 reviewer was added to this PR based on Keith Williams's automation. "Add ready-for-e2e label" took an action on this PR • (12/11/24)1 label was added to this PR based on Keith Williams's automation. |
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.
Code LGTM !!
E2E results are ready! |
What does this PR do?
UserListTable
is infinitely rendered when a filter value is set. This PR fixes it by fixing the implementation ofuseFetchMoreOnBottomReached
.Screenshot.2024-12-10.at.12.59.18.mp4
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
in
Checklist