Intersection Observer does not send an initial notification after .observe() is called by late-executing scripts.
Categories
(Core :: DOM: Core & HTML, defect, P3)
Tracking
()
People
(Reporter: calhounsm, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
369 bytes,
text/html
|
Details |
Comment 1•7 years ago
|
||
Updated•7 years ago
|
Updated•7 years ago
|
Updated•7 years ago
|
Updated•7 years ago
|
Comment 2•7 years ago
|
||
Updated•7 years ago
|
Updated•7 years ago
|
Comment 3•7 years ago
|
||
Comment 4•7 years ago
|
||
Comment 5•6 years ago
|
||
Comment 6•6 years ago
|
||
Comment 7•6 years ago
|
||
Comment 8•6 years ago
|
||
Comment 9•6 years ago
|
||
Comment 10•6 years ago
|
||
Assignee | ||
Updated•6 years ago
|
Comment 11•5 years ago
|
||
Chromium browsers always send at least one observation when observe is called().
Otherwise scripts will not be able to use this API reliably, because without this observation
they will not be able to reliably initialize the internal state of the object under observation.
For example, an would not know whether it intersects the viewport until some future
change happens to dirty rendering.
I've followed up with szager-chromium to see if a spec clarification needs to be made.
We landed commits specifically to ensure this is the case, and I'll post an update also
with any WPTs for this that exist.
Comment 12•5 years ago
|
||
s/an would/an ad would/
Comment 13•5 years ago
|
||
See resolution here:
https://github.com/w3c/IntersectionObserver/issues/426
"previousThresholdIndex gets an initial value of -1 for the express purpose of forcing a notification at the earliest opportunity, because the Run the Update Intersection Observations Steps procedure in the spec can never produce a thresholdIndex less than zero (see step 2.2.9)."
Comment 14•5 years ago
|
||
This Chromium CL implements, and adds tests. The tests in question were subsequently upstreamed to WPT.
Comment 15•5 years ago
|
||
Looks like Tobias already fixed the case in bug 1335644. And the test case in comment 0 works fine on the latest nightly. Maybe some refactoring by Emilio addressed this issue? Or am I missing something?
I will try the web platform tests on the nightly.
Comment 16•5 years ago
|
||
I am confused. IIUC, one of the test case is here in edge-inclusive-intersection.html, and it's been passed since Tobias fixed bug 1335644. Is this still an issue?
Comment 17•5 years ago
|
||
Quick update: first, thanks for testing all the examples.
Second: I asked some more questions internally at Google and it seems that the issue is a bit hard to reproduce and happens most often in our automated testing of the product on Windows.
From my POV it's fine to just close this bug as fixed, since it sounds like a duplicate of issue 1335644. Some of the Google teams had found this bug and were unsure about whether the spec requires the behavior (which it does, hence 1335644). This bug being closed would make that more clear.
Comment 18•5 years ago
|
||
chrishtr, thanks for the info. That's super helpful!
(In reply to chrishtr from comment #17)
Quick update: first, thanks for testing all the examples.
Second: I asked some more questions internally at Google and it seems that the issue is a bit hard to reproduce and happens most often in our automated testing of the product on Windows.
At least on our end, the test seems to have been stable. (An intermittent failure I could find is bug 1578639, but it's not related to this issue I think).
That said, Tobias said he could reproduce the original test case on Firefox 56 on his Mac in comment 2, then he said he can no longer reproduce the issue on Firefox 59. So, it's highly possible there was a race condition in Firefox as well. One thing come to mind was a micro task change (bug 1193394) but it landed in Firefox 60, so it's not.
From my POV it's fine to just close this bug as fixed, since it sounds like a duplicate of issue 1335644. Some of the Google teams had found this bug and were unsure about whether the spec requires the behavior (which it does, hence 1335644). This bug being closed would make that more clear.
Yeah, before I read https://github.com/w3c/IntersectionObserver/issues/165, I had a conclusion that IntersectionObserver shouldn't report the case. :)
Thanks for revisiting this issue, our issue. I am gong to close this.
Comment 19•5 years ago
|
||
I think smaug's first comment is the reall issue:
(In reply to Olli Pettay [:smaug] from comment #7)
So why is this even a valid bug? If anything hasn't changed in the page, per
HTML spec
https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-
model the document maybe removed from docs in 'Update the rendering' and
then observer isn't called.
Does Chrome do extra paints?
Specifically, step 11.4:
<quote>
Unnecessary rendering: Remove from docs all Document objects which meet both of the following conditions:
- The user agent believes that updating the rendering of the Document's browsing context would have no visible effect, and
- The Document's map of animation frame callbacks is empty.
</quote>
To answer smaug's question: yes, Chrome does an extra paint if there are any new observations that haven't generated a notification yet. We reasoned that the overhead of one extra paint (which is largely a no-op) is a worthwhile trade-off in this case.
This could be clarified by adding a third condition for removing a doc, along these lines:
- There are no Elements in any browsing context that have an IntersectionObserverRegistration in its RegisteredIntersectionObservers slot for which:
- The IntersectionObserver's root is in the DOM tree of the Document, and
- The previousThresholdIndex property is -1.
Comment 20•5 years ago
|
||
I filed a bug on the IntersectionObserver spec:
https://github.com/w3c/IntersectionObserver/issues/430
This does seem like something that should be resolved to ensure interoperability, as it seems to be an ongoing issue for at least some developers; for example:
Description
•