From fa644311c84e1ae65383782d7466e5783ecef98e Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 19 Jul 2021 09:24:18 -0400 Subject: [PATCH 1/2] fix(web-vitals): Check for valid entry in updatedCLS --- packages/tracing/src/browser/web-vitals/getCLS.ts | 2 +- packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/tracing/src/browser/web-vitals/getCLS.ts b/packages/tracing/src/browser/web-vitals/getCLS.ts index 5a45fd6eec27..7e3307ce3115 100644 --- a/packages/tracing/src/browser/web-vitals/getCLS.ts +++ b/packages/tracing/src/browser/web-vitals/getCLS.ts @@ -39,7 +39,7 @@ export const getCLS = (onReport: ReportHandler, reportAllChanges?: boolean): voi let report: ReturnType; const entryHandler = (entry: LayoutShift): void => { - if (!entry.hadRecentInput) { + if (entry && !entry.hadRecentInput) { (metric.value as number) += entry.value; metric.entries.push(entry); if (report) { diff --git a/packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts b/packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts index 061c0b0a5c76..35690d173ff8 100644 --- a/packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts +++ b/packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts @@ -43,7 +43,8 @@ export const getUpdatedCLS = (onReport: ReportHandler, reportAllChanges?: boolea const entryHandler = (entry: LayoutShift): void => { // Only count layout shifts without recent user input. - if (!entry.hadRecentInput) { + // TODO: Figure out why entry can be undefined + if (entry && !entry.hadRecentInput) { const firstSessionEntry = sessionEntries[0]; const lastSessionEntry = sessionEntries[sessionEntries.length - 1]; From 6300658043c956491896f76c3ce9711fa7885635 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 19 Jul 2021 10:49:30 -0400 Subject: [PATCH 2/2] fix: Make sure sessionEntries is a non-empty array --- packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts b/packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts index 35690d173ff8..5f5673a67ae1 100644 --- a/packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts +++ b/packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts @@ -53,6 +53,7 @@ export const getUpdatedCLS = (onReport: ReportHandler, reportAllChanges?: boolea // entry in the current session. Otherwise, start a new session. if ( sessionValue && + sessionEntries.length !== 0 && entry.startTime - lastSessionEntry.startTime < 1000 && entry.startTime - firstSessionEntry.startTime < 5000 ) {