From 2e3bb83d364bc53a3c392f4fa6831cfe5d726533 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Fri, 30 Aug 2024 13:29:35 +0100 Subject: [PATCH 1/5] Cap LCP download time --- src/attribution/onLCP.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/attribution/onLCP.ts b/src/attribution/onLCP.ts index 285f319a..678c4a23 100644 --- a/src/attribution/onLCP.ts +++ b/src/attribution/onLCP.ts @@ -54,9 +54,13 @@ const attributeLCP = (metric: LCPMetric): LCPMetricWithAttribution => { activationStart : 0, ); - const lcpResponseEnd = Math.max( - lcpRequestStart, - lcpResourceEntry ? lcpResourceEntry.responseEnd - activationStart : 0, + const lcpResponseEnd = Math.min( + Math.max( + lcpRequestStart, + lcpResourceEntry ? lcpResourceEntry.responseEnd - activationStart : 0, + ), + // Cap at LCP time (videos continue downloading after LCP for example) + lcpEntry.startTime - activationStart, ); const lcpRenderTime = Math.max( lcpResponseEnd, From 7e86a73f5e468b2c8f0b88a79273faa1c2d4562c Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Fri, 30 Aug 2024 13:31:31 +0100 Subject: [PATCH 2/5] Formatting --- src/attribution/onLCP.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/attribution/onLCP.ts b/src/attribution/onLCP.ts index 678c4a23..bf7c6aec 100644 --- a/src/attribution/onLCP.ts +++ b/src/attribution/onLCP.ts @@ -55,12 +55,12 @@ const attributeLCP = (metric: LCPMetric): LCPMetricWithAttribution => { : 0, ); const lcpResponseEnd = Math.min( + // Cap at LCP time (videos continue downloading after LCP for example) + lcpEntry.startTime - activationStart, Math.max( lcpRequestStart, lcpResourceEntry ? lcpResourceEntry.responseEnd - activationStart : 0, ), - // Cap at LCP time (videos continue downloading after LCP for example) - lcpEntry.startTime - activationStart, ); const lcpRenderTime = Math.max( lcpResponseEnd, From 0a2d2cc780d3c10fdf7793d48e42de68adbcf4ce Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Fri, 30 Aug 2024 19:47:40 +0100 Subject: [PATCH 3/5] Review feedback --- src/attribution/onLCP.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/attribution/onLCP.ts b/src/attribution/onLCP.ts index bf7c6aec..7c155de9 100644 --- a/src/attribution/onLCP.ts +++ b/src/attribution/onLCP.ts @@ -62,10 +62,7 @@ const attributeLCP = (metric: LCPMetric): LCPMetricWithAttribution => { lcpResourceEntry ? lcpResourceEntry.responseEnd - activationStart : 0, ), ); - const lcpRenderTime = Math.max( - lcpResponseEnd, - lcpEntry.startTime - activationStart, - ); + const lcpRenderTime = metric.value; attribution = { element: getSelector(lcpEntry.element), From 3693a82dc7d9426473af68ab93a769ad41f082ce Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Fri, 30 Aug 2024 19:54:29 +0100 Subject: [PATCH 4/5] Remove redundant renderTime const --- src/attribution/onLCP.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/attribution/onLCP.ts b/src/attribution/onLCP.ts index 7c155de9..294af7ec 100644 --- a/src/attribution/onLCP.ts +++ b/src/attribution/onLCP.ts @@ -62,14 +62,13 @@ const attributeLCP = (metric: LCPMetric): LCPMetricWithAttribution => { lcpResourceEntry ? lcpResourceEntry.responseEnd - activationStart : 0, ), ); - const lcpRenderTime = metric.value; attribution = { element: getSelector(lcpEntry.element), timeToFirstByte: ttfb, resourceLoadDelay: lcpRequestStart - ttfb, resourceLoadDuration: lcpResponseEnd - lcpRequestStart, - elementRenderDelay: lcpRenderTime - lcpResponseEnd, + elementRenderDelay: metric.value - lcpResponseEnd, navigationEntry, lcpEntry, }; From 0136440a98826bf4081bc401b78fa8ebb3348cc0 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Fri, 27 Sep 2024 11:14:31 +0100 Subject: [PATCH 5/5] Review feedback --- src/attribution/onLCP.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/attribution/onLCP.ts b/src/attribution/onLCP.ts index 294af7ec..cf7b4eee 100644 --- a/src/attribution/onLCP.ts +++ b/src/attribution/onLCP.ts @@ -56,7 +56,7 @@ const attributeLCP = (metric: LCPMetric): LCPMetricWithAttribution => { ); const lcpResponseEnd = Math.min( // Cap at LCP time (videos continue downloading after LCP for example) - lcpEntry.startTime - activationStart, + metric.value, Math.max( lcpRequestStart, lcpResourceEntry ? lcpResourceEntry.responseEnd - activationStart : 0,