Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tracing/src/browser/web-vitals/getCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getCLS = (onReport: ReportHandler, reportAllChanges?: boolean): voi
let report: ReturnType<typeof bindReporter>;

const entryHandler = (entry: LayoutShift): void => {
if (!entry.hadRecentInput) {
if (entry && !entry.hadRecentInput) {
(metric.value as number) += entry.value;
metric.entries.push(entry);
if (report) {
Expand Down
4 changes: 3 additions & 1 deletion packages/tracing/src/browser/web-vitals/getUpdatedCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AbhiPrasad you'll also want to check if sessionEntries is a non-empty array on line 54. lastSessionEntry could be undefined as well

const firstSessionEntry = sessionEntries[0];
const lastSessionEntry = sessionEntries[sessionEntries.length - 1];

Expand All @@ -52,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
) {
Expand Down