Skip to content

Commit

Permalink
πŸ‘Œ Clarify that the CLS is the max value
Browse files Browse the repository at this point in the history
  • Loading branch information
webNeat committed Sep 6, 2021
1 parent 0268939 commit 6dd854d
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ function trackActivityLoadingTime(
* Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/master/src/getCLS.ts
*/
function trackCumulativeLayoutShift(lifeCycle: LifeCycle, callback: (layoutShift: number) => void) {
let clsValue = 0
let maxClsValue = 0
const window = slidingSessionWindow()
const { unsubscribe: stop } = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, (entry) => {
if (entry.entryType === 'layout-shift' && !entry.hadRecentInput) {
window.update(entry)
if (window.value() > clsValue) {
clsValue = window.value()
callback(round(clsValue, 4))
if (window.value() > maxClsValue) {
maxClsValue = window.value()
callback(round(maxClsValue, 4))
}
}
})
Expand Down

0 comments on commit 6dd854d

Please sign in to comment.