Skip to content

Commit

Permalink
check both container timing and element timing
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilliams720 committed Nov 22, 2024
1 parent 31e8bda commit 171ca3c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion polyfill/polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class ContainerPerformanceObserver implements PerformanceObserver {
// There's a weird bug where we sometimes get a load of empty rects (all zero'd out)
// https://issues.chromium.org/issues/379844652
// https://github.com/bloomberg/container-timing/issues/8
// The other reason this can happen is if an element renders "off screen", which is expected behavior (test case: https://fluoridated-bow-church.glitch.me/)
if (ContainerPerformanceObserver.isEmptyRect(entry.intersectionRect)) {
return;
}
Expand Down Expand Up @@ -481,7 +482,11 @@ class ContainerPerformanceObserver implements PerformanceObserver {

const closestRoot = element.closest(containerTimingAttrSelector);
if (
element.getAttribute("elementtiming") === INTERNAL_ATTR_NAME &&
// We should check the element is directly a `containertiming` element or
// its one of our own `elementtiming` elements which we polyfilled
// The former is because you can apply `containertiming` to a <p> and it should still work
(element.getAttribute("elementtiming") === INTERNAL_ATTR_NAME ||
element.hasAttribute("containertiming")) &&
closestRoot
) {
this.emitNewAreaPainted(entry as PerformanceElementTiming, closestRoot);
Expand Down

0 comments on commit 171ca3c

Please sign in to comment.