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(InfiniteScroll): fixed the double onActivate in the InfiniteScroll component #81

Merged
merged 5 commits into from
Jul 25, 2023

Conversation

Ruminat
Copy link
Contributor

@Ruminat Ruminat commented Jul 24, 2023

Issue: #80
Solution: added a small delay after the first onActivate so that the second (wrong) one won't be called.

@gravity-ui-bot
Copy link
Contributor

Preview is ready.

Copy link
Contributor

@korvin89 korvin89 left a comment

Choose a reason for hiding this comment

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

Why is it called multiple times? Apparently, you want to fix the consequence of the problem, not the problem itself.

@Ruminat
Copy link
Contributor Author

Ruminat commented Jul 24, 2023

Why is it called multiple times?

Because the isBottomVisible condition doesn't change instantly and the isActive condition does which allows the second onActivate to happen. But while the second onActivate is being processed, the isBottomVisible condition finally changes so we won't get any new onActivate's

image

@Ruminat
Copy link
Contributor Author

Ruminat commented Jul 24, 2023

It's IntersectionObserver which changes isBottomVisible, so I'm not sure if we can do anything about that

@Ruminat
Copy link
Contributor Author

Ruminat commented Jul 24, 2023

Or maybe we can do another check (if the intersector is visible) together with the isActive check
I will investigate more

@Ruminat
Copy link
Contributor Author

Ruminat commented Jul 25, 2023

@korvin89 I found a more elegant solution:

  • I got rid of the useEffect in the InfiniteScroll component
  • Renamed useIntersectionuseOnIntersected
  • useOnIntersected now triggers an onIntersected callback, so that we will check and call onActivate only when isIntersecting becomes true
  • That way we don't get the double onActivate and everything else works as expected

@Ruminat Ruminat merged commit 1cc0bd6 into main Jul 25, 2023
3 checks passed
@Ruminat Ruminat deleted the fix-double-onActivate-in-InfiniteScroll branch July 25, 2023 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants