@@ -151,7 +151,9 @@ Source attribution {#source-attribution}
151151
152152In addition to the layout shift value, the API reports a sampling of up to five
153153DOM 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
156158It is possible that the true "root cause" of instability will be only
157159indirectly 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.
449457All 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+
452465A 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+
5715931. 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