-
Notifications
You must be signed in to change notification settings - Fork 23k
Update LayoutShiftAttribution documentation for impact-area ordering #42145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update LayoutShiftAttribution documentation for impact-area ordering #42145
Conversation
| - : Returns a JSON representation of the `LayoutShiftAttribution` object. | ||
|
|
||
| ## Examples | ||
| The following example observes layout shifts and identifies the most impactful element. The `sources` array is sorted by impact area in descending order, so the first element (`sources[0]`) represents the element that contributed most to the layout shift. For more detail on this see [Debug Web Vitals in the field](https://web.dev/articles/debug-performance-in-the-field). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
| The following example observes layout shifts and identifies the most impactful element. The `sources` array is sorted by impact area in descending order, so the first element (`sources[0]`) represents the element that contributed most to the layout shift. For more detail on this see [Debug Web Vitals in the field](https://web.dev/articles/debug-performance-in-the-field). |
| The following example observes layout shifts and identifies the most impactful element. The `sources` array is sorted by impact area in descending order, so the first element (`sources[0]`) represents the element that contributed most to the layout shift. For more detail on this see [Debug Web Vitals in the field](https://web.dev/articles/debug-performance-in-the-field). | ||
|
|
||
| The following example finds the element with the highest layout shift score, and returns the element in that entry with the largest size prior to the shift (`previousRect`). For more detail on this see [Debug Web Vitals in the field](https://web.dev/articles/debug-performance-in-the-field). | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
| The following example observes layout shifts and identifies the most impactful element. The `sources` array is sorted by impact area in descending order, so the first element (`sources[0]`) represents the element that contributed most to the layout shift. For more detail on this see [Debug Web Vitals in the field](https://web.dev/articles/debug-performance-in-the-field). | |
| const observer = new PerformanceObserver((list) => { | ||
| for (const entry of list.getEntries()) { | ||
| if (!entry.sources || entry.sources.length === 0) continue; | ||
|
|
||
| const mostImpactfulSource = entry.sources[0]; | ||
| console.log("Layout shift score:", entry.value); | ||
| console.log("Most impactful element:", largestShiftSource.node); | ||
| console.log("Previous position:", largestShiftSource.previousRect); | ||
| console.log("Current position:", largestShiftSource.currentRect); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| observer.observe({ type: "layout-shift", buffered: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
| const observer = new PerformanceObserver((list) => { | |
| for (const entry of list.getEntries()) { | |
| if (!entry.sources || entry.sources.length === 0) continue; | |
| const mostImpactfulSource = entry.sources[0]; | |
| console.log("Layout shift score:", entry.value); | |
| console.log("Most impactful element:", largestShiftSource.node); | |
| console.log("Previous position:", largestShiftSource.previousRect); | |
| console.log("Current position:", largestShiftSource.currentRect); | |
| } | |
| } | |
| } | |
| }); | |
| observer.observe({ type: "layout-shift", buffered: true }); | |
| const observer = new PerformanceObserver((list) => { | |
| for (const entry of list.getEntries()) { | |
| if (!entry.sources || entry.sources.length === 0) continue; | |
| const mostImpactfulSource = entry.sources[0]; | |
| console.log("Layout shift score:", entry.value); | |
| console.log("Most impactful element:", largestShiftSource.node); | |
| console.log("Previous position:", largestShiftSource.previousRect); | |
| console.log("Current position:", largestShiftSource.currentRect); | |
| } | |
| }); | |
| observer.observe({ type: "layout-shift", buffered: true }); |
|
Howdy — this has linter failures that need to be resolved. |
Description
Updates the
LayoutShiftAttributioninterface documentation to reflect the standardization of impact-area ordering forLayoutShift.sources, as implemented in Chrome 143.Motivation
The Chromium team has defined a standardized ordering for
LayoutShiftAttributionentries based on impact area to ensure consistent and predictable behavior across browser implementations.This documentation update helps developers understand how layout shift sources are ordered and what behavior they can reliably expect when using the Performance API to analyze layout shifts.
Additional details
Related issues and pull requests
N/A