Skip to content
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

fix(web-vitals): Check for valid entry in updatedCLS #3816

Merged
merged 3 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 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 Down