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

IntersectionObserver entries inaccurate #24287

Open
robert-williams-ast opened this issue Feb 8, 2023 · 1 comment
Open

IntersectionObserver entries inaccurate #24287

robert-williams-ast opened this issue Feb 8, 2023 · 1 comment
Labels
area: Resize/Intersection Observer Content:WebAPI Web API docs effort: medium This task is a medium effort. help wanted If you know something about this topic, we would love your help!

Comments

@robert-williams-ast
Copy link

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API

What specific section or headline is this issue about?

Targeting an element to be observed

What information was incorrect, unhelpful, or incomplete?

The list of entries received by the callback includes one entry for each target which reported a change in its intersection status.

What did you expect to see?

The list of entries received by the callback includes at least one entry for each target which reported a change in its intersection status. Multiple intersection changes may be reported in the same event.

either:

Check the time property to see in which order the changes occur.

or:

The entries will be listed ordered from first to last.

Do you have any supporting links, references, or citations?

I will write a test.

Something like this should work on any page with reasonable complexity and length.

[...document.querySelectorAll('*')].forEach((element) => {
  new IntersectionObserver((entries) => {
    entries.forEach(entry => console.log('intersectionRatio', entry.intersectionRatio ));
    if (entries[0].target === entries[1]?.target) {
      debugger;
    }
  });
});

and then grab the scroll-bar and crank up and down an few times.

Do you have anything more you want to share?

I do not know wether the entries are always in chronological order. Please advise.

MDN metadata

Page report details
@robert-williams-ast robert-williams-ast added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Feb 8, 2023
@github-actions github-actions bot added the Content:WebAPI Web API docs label Feb 8, 2023
@sideshowbarker sideshowbarker added help wanted If you know something about this topic, we would love your help! effort: medium This task is a medium effort. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Feb 10, 2023
@seanmacisaac
Copy link

We hit a bug yesterday due our code making the assumption about only getting a single entry per target in any particular callback invocation. We fixed our code not even knowing if it could be the issue and added some logging that showed that it was happening. We later read the spec on the W3C site and it showed that it could happen:

https://w3c.github.io/IntersectionObserver/#update-intersection-observations-algo
https://w3c.github.io/IntersectionObserver/#queue-intersection-observer-entry-algo
https://w3c.github.io/IntersectionObserver/#notify-intersection-observers-algo

The spec doesn't seem to explicitly state that the entries will be in chronological order, but does talk about using queues and I think implies it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Resize/Intersection Observer Content:WebAPI Web API docs effort: medium This task is a medium effort. help wanted If you know something about this topic, we would love your help!
4 participants