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

✨ [RUMF-777] implement Cumulative Layout Shift #628

Merged
merged 6 commits into from
Nov 24, 2020

Conversation

BenoitZugmeyer
Copy link
Member

Motivation

Expose the web-vitals CLS on all views

Changes

  • Implement CLS tracking

Testing

CI + manual tests


I have gone over the contributing documentation.

@BenoitZugmeyer BenoitZugmeyer requested a review from a team as a code owner November 23, 2020 13:28
Comment on lines 138 to 141
const { stop: stopCLSTracking } = trackLayoutShift(lifeCycle, (layoutShift) => {
cumulativeLayoutShift = (cumulativeLayoutShift || 0) + layoutShift
scheduleViewUpdate()
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { stop: stopCLSTracking } = trackLayoutShift(lifeCycle, (layoutShift) => {
cumulativeLayoutShift = (cumulativeLayoutShift || 0) + layoutShift
scheduleViewUpdate()
})
if (isLayoutShiftSupported()) {
cumulativeLayoutShift = 0
const { stop: stopCLSTracking } = trackLayoutShift(lifeCycle, (layoutShift) => {
cumulativeLayoutShift = cumulativeLayoutShift + layoutShift
scheduleViewUpdate()
})
}

then we would avoid to handle undefined case in callback.
It could probably remove the need to check the support in the track function.

Copy link
Member Author

@BenoitZugmeyer BenoitZugmeyer Nov 23, 2020

Choose a reason for hiding this comment

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

We still need to handle the undefined case (for typings), but it's a bit easier to follow, so I just used a ! operator. 👍

Copy link
Contributor

@bcaudan bcaudan left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants