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

useIntersectionObserver received 2 entries, but only the first (outdated) is taken #271

Closed
reinos opened this issue Dec 27, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@reinos
Copy link

reinos commented Dec 27, 2022

Hi,

First of all, what a great library of hooks, well done!

Currently I have an issue with the intersectionObserver. In Chrome (not in FF nor Safari) I receive 2 entries in the callback. The first entry has isIntersecting : false and the second has isIntersecting: true. Im not sure why I receive 2 entries via the Intersection callback, but it seems that the first one is obsolete (outdated) and the latest one is the most up to date with the DOM.

So I feel that the implementation here https://github.com/juliencrn/usehooks-ts/blob/master/src/useIntersectionObserver/useIntersectionObserver.ts#L20-L22 of just getting the first entry is wrong. I think this should just catch the latest one. As it seems there are situations where the Intersection callback can give more than one result and where latests one is always the one that is up-to-date.

@qinbinhua601
Copy link

@reinos I somehow encountered the same problem occasionally but could not find the 100% reproduce step. Would you please share the reproduce step on how to reproduce it in a minimal demo. Thanks in advance. 😄 😄 😄

@juliencrn juliencrn added the bug Something isn't working label Jan 7, 2024
@juliencrn
Copy link
Owner

Hi, thanks for the feedback!
I've pushed a PR that should fix it, feel free to give a code review on it.
See #464

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants