Skip to content

Commit 0252b44

Browse files
committed
Update docs to mention layout shift sources being sorted by impact area
1 parent 3675a56 commit 0252b44

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

index.bs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ Source attribution {#source-attribution}
151151

152152
In addition to the layout shift value, the API reports a sampling of up to five
153153
DOM elements whose layout shifts most substantially contributed to the layout
154-
shift value for an animation frame.
154+
shift value for an animation frame. The <a href="#dom-layoutshift-sources">sources</a>
155+
are sorted by impact area in descending order, so the first element represents
156+
the element that contributed most to the layout shift.
155157

156158
It is possible that the true "root cause" of instability will be only
157159
indirectly related to the DOM element that experiences a layout shift.
@@ -186,6 +188,12 @@ Usage example {#example}
186188
timestamp: entry.startTime
187189
});
188190
cumulativeLayoutShiftScore += entry.value;
191+
192+
// Sources are sorted by impact area in descending order.
193+
// The first element contributed most to the layout shift.
194+
if (entry.sources && entry.sources.length > 0) {
195+
console.log('Largest contributing element:', entry.sources[0].node);
196+
}
189197
}
190198
}
191199

@@ -449,6 +457,11 @@ events are also not excluding inputs.
449457
All attributes have the values which are assigned to them by the steps to
450458
<a>report the layout shift</a>.
451459

460+
The <dfn attribute for=LayoutShift>sources</dfn> attribute returns a
461+
{{FrozenArray}} of {{LayoutShiftAttribution}} objects, sorted in descending order
462+
by impact area. The first element has the largest <a>node impact region</a> and
463+
represents the element that contributed most to the layout shift.
464+
452465
A user agent implementing the Layout Instability API must include
453466
<code>"layout-shift"</code> in {{PerformanceObserver/supportedEntryTypes}} for
454467
<a href="https://html.spec.whatwg.org/multipage/window-object.html#the-window-object">Window</a>
@@ -568,6 +581,15 @@ When asked to <dfn>report the layout shift sources</dfn> for an active
568581
<a href="https://infra.spec.whatwg.org/#list-replace">replace</a>
569582
|smallest| with |N| in |C|.
570583

584+
1. <a href="https://infra.spec.whatwg.org/#list-sort-in-descending-order">Sort</a>
585+
|C| in descending order, with |a| being less than |b| if the area
586+
of the <a>node impact region</a> of |a| is less than the area
587+
of the <a>node impact region</a> of |b|.
588+
589+
NOTE: This ensures that the <a href="#dom-layoutshift-sources">sources</a>
590+
attribute exposes layout shift sources in descending order by impact area,
591+
with the element that contributed most to the layout shift appearing first.
592+
571593
1. Return a {{FrozenArray}} of {{LayoutShiftAttribution}} objects created
572594
by running the algorithm to <a>create the attribution</a> once
573595
for each member of |C|.

0 commit comments

Comments
 (0)