ladybird/Tests/LibWeb/Text/input/IntersectionObserver/observe-after-load-fires-initial-callback.html
Aliaksandr Kalenik a5d1703486 LibWeb: Schedule a frame when IntersectionObserver starts observing
Since rendering updates moved to on-demand scheduling, observing a
target no longer fires the initial intersection callback unless
something else happens to request a frame. Kick the frame timer from
observe() so the update-the-rendering steps run and deliver the initial
entry.
2026-04-30 21:14:03 +02:00

27 lines
883 B
HTML

<!DOCTYPE html>
<style>
#target {
width: 100px;
height: 100px;
background: red;
}
</style>
<script src="../include.js"></script>
<div id="target"></div>
<script>
asyncTest(done => {
// Calling observe() after the page has fully loaded should still trigger
// an initial intersection callback on the next rendering opportunity.
window.addEventListener("load", () => {
// Defer past the load event so any frame requested by the loading
// pipeline has already been dispatched.
setTimeout(() => {
let observer = new IntersectionObserver(entries => {
println(`isIntersecting=${entries[0].isIntersecting}`);
done();
});
observer.observe(document.getElementById("target"));
}, 100);
});
});
</script>