Skip to content

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

Merged
domenic merged 14 commits into
masterfrom
zcorpan/lazy-check-in-event-loop
May 19, 2020
Merged

Check intersection of lazy images from "update the rendering"#5510
domenic merged 14 commits into
masterfrom
zcorpan/lazy-check-in-event-loop

Conversation

@zcorpan

@zcorpan zcorpan commented May 5, 2020

Copy link
Copy Markdown
Member

@zcorpan
zcorpan force-pushed the zcorpan/lazy-check-in-event-loop branch from df30593 to c0a7bb5 Compare May 5, 2020 13:39
Comment thread source Outdated

@domfarolino domfarolino left a comment

Copy link
Copy Markdown
Member

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.

Comment thread source Outdated
Comment thread source Outdated
@zcorpan

zcorpan commented May 6, 2020

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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

zcorpan commented May 7, 2020

Copy link
Copy Markdown
Member Author

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

@zcorpan

zcorpan commented May 7, 2020

Copy link
Copy Markdown
Member Author

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?

@domfarolino domfarolino left a comment

Copy link
Copy Markdown
Member

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 #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

Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
@zcorpan

zcorpan commented May 8, 2020

Copy link
Copy Markdown
Member Author

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

zcorpan commented May 8, 2020

Copy link
Copy Markdown
Member Author

cc @rwlbuis @smfr

Comment thread source Outdated
@zcorpan

zcorpan commented May 8, 2020

Copy link
Copy Markdown
Member Author

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

emilio commented May 8, 2020

Copy link
Copy Markdown
Contributor

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

Comment thread source
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
@domfarolino

Copy link
Copy Markdown
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

zcorpan commented May 14, 2020

Copy link
Copy Markdown
Member Author

Thanks @domfarolino, LGTM

@annevk annevk left a comment

Copy link
Copy Markdown
Member

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.

Comment thread source Outdated
Comment thread source Outdated
Comment thread source
@domenic

domenic commented May 14, 2020

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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

@domenic domenic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking pretty nice!

Comment thread source Outdated
Comment thread source
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
@zcorpan

zcorpan commented May 18, 2020

Copy link
Copy Markdown
Member Author

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

Follow-up cleanup tasks will be:

@domfarolino domfarolino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, looks good!

@zcorpan

zcorpan commented May 19, 2020

Copy link
Copy Markdown
Member Author

@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