mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1619858 - Use an intersection observer per document for lazyload. r=hiro
We can't observe when the sub-document gets detached from the root document to drop the observation, so this is the sound thing to do. Differential Revision: https://phabricator.services.mozilla.com/D65362 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
9bc071f817
commit
921890154c
@ -14688,19 +14688,14 @@ void Document::NotifyIntersectionObservers() {
|
||||
}
|
||||
|
||||
DOMIntersectionObserver* Document::GetLazyLoadImageObserver() {
|
||||
Document* rootDoc = nsContentUtils::GetRootDocument(this);
|
||||
MOZ_ASSERT(rootDoc);
|
||||
|
||||
if (rootDoc->mLazyLoadImageObserver) {
|
||||
return rootDoc->mLazyLoadImageObserver;
|
||||
if (!mLazyLoadImageObserver) {
|
||||
if (nsPIDOMWindowInner* inner = GetInnerWindow()) {
|
||||
mLazyLoadImageObserver =
|
||||
DOMIntersectionObserver::CreateLazyLoadObserver(inner);
|
||||
}
|
||||
}
|
||||
|
||||
if (nsPIDOMWindowInner* inner = rootDoc->GetInnerWindow()) {
|
||||
rootDoc->mLazyLoadImageObserver =
|
||||
DOMIntersectionObserver::CreateLazyLoadObserver(inner);
|
||||
}
|
||||
|
||||
return rootDoc->mLazyLoadImageObserver;
|
||||
return mLazyLoadImageObserver;
|
||||
}
|
||||
|
||||
static CallState NotifyLayerManagerRecreatedCallback(Document& aDocument,
|
||||
|
@ -0,0 +1,26 @@
|
||||
<!doctype html>
|
||||
<html class="test-wait">
|
||||
<title>Crash when detaching a frame during a lazy-load operation</title>
|
||||
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
|
||||
<link rel="author" href="https://mozilla.org" title="Mozilla">
|
||||
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1619858">
|
||||
<iframe srcdoc=""></iframe>
|
||||
<script>
|
||||
onload = function() {
|
||||
let frame = document.querySelector("iframe");
|
||||
frame.contentDocument.body.innerHTML = `
|
||||
<div style="height: 300vh"></div>
|
||||
<img loading="lazy" src="/images/blue96x96.png" width=96 height=96>
|
||||
`;
|
||||
let img = frame.contentDocument.querySelector("img");
|
||||
new IntersectionObserver(() => {
|
||||
frame.remove();
|
||||
requestAnimationFrame(function() {
|
||||
requestAnimationFrame(function() {
|
||||
document.documentElement.className = "";
|
||||
});
|
||||
});
|
||||
}).observe(img);
|
||||
frame.contentWindow.scrollTo(0, img.getBoundingClientRect().top);
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user