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

Check intersection of lazy images from "update the rendering" #5510

Merged
merged 14 commits into from
May 19, 2020

Conversation

zcorpan
Copy link
Member

@zcorpan zcorpan commented May 5, 2020

@zcorpan zcorpan force-pushed the zcorpan/lazy-check-in-event-loop branch from df30593 to c0a7bb5 Compare May 5, 2020 13:39
source Outdated Show resolved Hide resolved
Copy link
Member

@domfarolino domfarolino left a comment

Choose a reason for hiding this comment

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

I'm confused with this approach. My understanding of #5236 is that we sort of resolved to go with option (1) from the original post, where we use the Intersection Observer spec, instead of adding something extra to the update the rendering steps, and having a per-document list of lazy loaded images.

source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
@zcorpan
Copy link
Member Author

zcorpan commented May 6, 2020

Per #5236 (comment) , my understanding was that we only want to start observing in the update the rendering. But maybe I was overthinking it. Should the "update the image data" add lazy images to an intersection observer directly?

@domfarolino
Copy link
Member

Per #5236 (comment) , my understanding was that we only want to start observing in the update the rendering.

I think from updating-the-image-data if loading=lazy, we always want to observe the image, so that the update-the-rendering resumes the updating-the-image-data algorithm.

I'm commenting on how we observe the image, not so much when. My understanding from #5236 is that we don't want to create a per-document image list, and add a new step to update-the-rendering. Instead, from updating-the-image-data, we want to create and attach an Intersection Observer, and not add anything to the updating-the-image-data. That way the next time update-the-rendering runs, we just delegate to the Intersection Observer steps, instead of our own custom logic. Does that make sense? Please see @domenic's comment: #5236 (comment)

I'm happy to take on this approach, as it is pretty complicated and interesting to me. Or if you want to adjust this PR to do so, that's fine too.

@zcorpan
Copy link
Member Author

zcorpan commented May 7, 2020

Thanks for the explanation! It makes sense to me now. I'll update the PR.

@zcorpan
Copy link
Member Author

zcorpan commented May 7, 2020

OK, please take a look.

I set the root to the document, and left rootMargin and threshold UA-defined.

I realized now though that IntersectionObserver can only initialize rootMargin, and then it's read-only. Per #5408 (comment) , I think it needs to be changeable somehow?

Copy link
Member

@domfarolino domfarolino left a comment

Choose a reason for hiding this comment

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

I still have to take a closer look at some edge cases, but overall looking decent. Regarding some of the checkboxes in the main comment:

  • I think we can check the "at least two implementers agree [...]", given that this is mostly a spec refactoring, and and Chrome (me) and Firefox (@emilio) agree with the change, as per discussion in Lazy load intersection-checking should not be done in-parallel #5236.
  • There are no implementation bugs to be filed, since we're just aligning the spec to what implementations are already doing, so that can probably be checked

source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
@zcorpan
Copy link
Member Author

zcorpan commented May 8, 2020

I realized now though that IntersectionObserver can only initialize rootMargin, and then it's read-only. Per #5408 (comment) , I think it needs to be changeable somehow?

Filed w3c/IntersectionObserver#428

@zcorpan
Copy link
Member Author

zcorpan commented May 8, 2020

cc @rwlbuis @smfr

source Show resolved Hide resolved
@zcorpan
Copy link
Member Author

zcorpan commented May 8, 2020

There are no implementation bugs to be filed, since we're just aligning the spec to what implementations are already doing, so that can probably be checked

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/8073

It seems in both Chromium and Gecko, root is the implicit root. Is that what we want? This PR sets it to the image's node document. Using the implicit root takes away the rootMargin if the origins aren't similar-origin, per IntersectionObserver spec (for images in nested browsing contexts).

@emilio
Copy link
Contributor

emilio commented May 8, 2020

Yes, that's what you want since otherwise you load images inside iframes that are out of view.

source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
@domfarolino
Copy link
Member

I think I've addressed all major reviews in this with my latest commit, would appreciate if another owner took a look (@annevk ?)

@domfarolino domfarolino requested a review from annevk May 13, 2020 19:58
@zcorpan
Copy link
Member Author

zcorpan commented May 14, 2020

Thanks @domfarolino, LGTM

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

I thought we had discussed this (though maybe only with Dominic), but we should not add new points where we instantiate JavaScript objects or call their methods.

source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
@domenic
Copy link
Member

domenic commented May 14, 2020

we should not add new points where we instantiate JavaScript objects or call their methods.

Although I agree in general, I'm not sure whether we should block this work on that. It seems like it would require a large refactoring of the IntersectionObserver spec.

A middle ground might be to add awkward disclaimers everywhere, e.g. "new IntersectionObserver instance (using the original value of the IntersectionObserver constructor)", "For each entry in entries (using a method of iteration which does not trigger developer-modifiable array accessors or iteration hooks)", "if entry.isIntersecting is true (using the original value of the isIntersecting getter)", etc.

But, I guess if we could pull off the refactoring, that would be much nicer...

@domfarolino
Copy link
Member

I agree with the comments around using the DOM-exposed method names and objects. This was originally brought up in #5510 (comment), and we filed w3c/IntersectionObserver#427 for it.

But yeah, until that gets addressed I agree with making notes in the spec that explain what we're trying to do, and pointing to that issue to track the IO refactoring. For now I've added one around using the IntersectionObserver constructor, and I'll add more around the other parts @domenic mentioned.

@domfarolino
Copy link
Member

I've added some more <p class="XXX">'s describing that dom-IntersectionObserver* references should use the original values etc. I think this is ready for review

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Looking pretty nice!

source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
@zcorpan
Copy link
Member Author

zcorpan commented May 18, 2020

Thanks, @domenic! I've addressed your comments.

Follow-up cleanup tasks will be:

Copy link
Member

@domfarolino domfarolino left a comment

Choose a reason for hiding this comment

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

Thanks, looks good!

@zcorpan
Copy link
Member Author

zcorpan commented May 19, 2020

@domenic can you do the honors? 🙂

@domenic domenic merged commit 351d56a into master May 19, 2020
@domenic domenic deleted the zcorpan/lazy-check-in-event-loop branch May 19, 2020 18:10
@domfarolino domfarolino mentioned this pull request May 26, 2020
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Lazy load intersection-checking should not be done in-parallel
6 participants