Skip to content
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

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Dec 10, 2024

What does this PR do?

UserListTable is infinitely rendered when a filter value is set. This PR fixes it by fixing the implementation of useFetchMoreOnBottomReached.


Screenshot.2024-12-10.at.12.59.18.mp4

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A - I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Make sure "fetch more" works
  • Doesn't rerender infinitely when all the rows are already fetched

in

  • organization member list
  • team member list
  • insights routing form responses

Checklist

@keithwillcode keithwillcode added consumer core area: core, team members only labels Dec 10, 2024
Comment on lines +5 to +25
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]
Copy link
Contributor Author

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.

@eunjae-lee eunjae-lee marked this pull request as ready for review December 10, 2024 15:25
@graphite-app graphite-app bot requested a review from a team December 10, 2024 15:25
@dosubot dosubot bot added the 🐛 bug Something isn't working label Dec 10, 2024
Copy link

graphite-app bot commented Dec 10, 2024

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.

Copy link
Member

@hariombalhara hariombalhara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM !!

@PeerRich PeerRich enabled auto-merge (squash) December 11, 2024 13:31
Copy link
Contributor

github-actions bot commented Dec 11, 2024

E2E results are ready!

@PeerRich PeerRich merged commit 7d2523e into main Dec 11, 2024
88 of 110 checks passed
@PeerRich PeerRich deleted the fix/data-table-rerendering branch December 11, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working consumer core area: core, team members only ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants