-
Notifications
You must be signed in to change notification settings - Fork 145
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
CLS tracking: change source attribution logic and include devicePixelRatio
inside performance.cls
namespace
#3377
base: main
Are you sure you want to change the base?
Conversation
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3377 +/- ##
==========================================
- Coverage 92.81% 92.80% -0.01%
==========================================
Files 299 299
Lines 7860 7864 +4
Branches 1790 1792 +2
==========================================
+ Hits 7295 7298 +3
- Misses 565 566 +1 ☔ View full report in Codecov by Sentry. |
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
…rformance.cls namespace
devicePixelRatio
inside performance.cls
namespace
@@ -306,6 +310,7 @@ describe('trackCumulativeLayoutShift', () => { | |||
it('should get the target element, time, and rects of the largest layout shift', () => { | |||
startCLSTracking() | |||
const divElement = appendElement('<div id="div-element"></div>') | |||
const spanElement = appendElement('<span id="span-element"></span>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: what about naming this something like largerElement
?
This way, it gives a clue as why this is the element that is attributed to the CLS?
const spanElement = appendElement('<span id="span-element"></span>') | |
const largerElement = appendElement('<span id="larger-element"></span>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, good idea! change made here
@@ -306,6 +310,7 @@ describe('trackCumulativeLayoutShift', () => { | |||
it('should get the target element, time, and rects of the largest layout shift', () => { | |||
startCLSTracking() | |||
const divElement = appendElement('<div id="div-element"></div>') | |||
const spanElement = appendElement('<span id="span-element"></span>') | |||
|
|||
// first session window: { value: 0.5, time: 1, targetSelector: '#div-element' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ question: I guess this comment is not correct anymore? Is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah definitely! I'm removing it here
@@ -74,10 +75,10 @@ export function trackCumulativeLayoutShift( | |||
continue | |||
} | |||
|
|||
const { cumulatedValue, isMaxValue } = window.update(entry) | |||
const { cumulatedValue, isMaxValue, devicePixelRatio } = window.update(entry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ question: Does devicePixelRatio
changes over time? Otherwise, it's not needed to get it from the sliding window update (window.update(entry)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the user can change the screen within the same view, and the devicePixelRatio
can vary depending on the screen.
This is why I wanted to attach it to the moment where the CLS maxValue is reported.
I'd be happy to hear from your suggestions if you think it is a better way of doing it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 true, but it's not calculated depending on previous values from the sliding window.
I think what you want is to store devicePixelRatio
at the time of the max value (i.e. in the if (isMaxValue)
condition), the same way it is done for attribution = getBiggestElementAttribution()
I'm adding some suggestion comments here and here, so you see what I mean.
(source): source is RumLayoutShiftAttribution & { node: Element } => !!source.node && isElementNode(source.node) | ||
) | ||
if (elementNodeSources.length > 0) { | ||
return elementNodeSources.reduce(function (a, b) { | ||
return a.node && a.previousRect?.width * a.previousRect?.height > b.previousRect?.width * b.previousRect?.height |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: I think we don't need to check a.node
again as it's seems elementNodeSources
is already filtering out object without the node
property, no?
return a.node && a.previousRect?.width * a.previousRect?.height > b.previousRect?.width * b.previousRect?.height | |
return a.previousRect?.width * a.previousRect?.height > b.previousRect?.width * b.previousRect?.height |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true! fixed here
(source): source is RumLayoutShiftAttribution & { node: Element } => !!source.node && isElementNode(source.node) | ||
) | ||
if (elementNodeSources.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥜 nitpick: use early returns, it makes it easier to read.
if (elementNodeSources.length > 0) { | |
if (elementNodeSources.length <= 0) { | |
return | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here
Thanks @anediaz, Could you please update DataDog/rum-events-format to add the new property? |
Thanks for the explanation! |
@@ -74,10 +75,10 @@ export function trackCumulativeLayoutShift( | |||
continue | |||
} | |||
|
|||
const { cumulatedValue, isMaxValue } = window.update(entry) | |||
const { cumulatedValue, isMaxValue, devicePixelRatio } = window.update(entry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 true, but it's not calculated depending on previous values from the sliding window.
I think what you want is to store devicePixelRatio
at the time of the max value (i.e. in the if (isMaxValue)
condition), the same way it is done for attribution = getBiggestElementAttribution()
I'm adding some suggestion comments here and here, so you see what I mean.
@@ -96,6 +97,7 @@ export function trackCumulativeLayoutShift( | |||
time: biggestShift?.time, | |||
previousRect: biggestShift?.previousRect ? asRumRect(biggestShift.previousRect) : undefined, | |||
currentRect: biggestShift?.currentRect ? asRumRect(biggestShift.currentRect) : undefined, | |||
devicePixelRatio, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
devicePixelRatio, | |
devicePixelRatio = biggestShift?.devicePixelRatio, |
biggestShift = { | ||
target: attribution?.node ? new WeakRef(attribution.node) : undefined, | ||
time: elapsed(viewStart, entry.startTime), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
biggestShift = { | |
target: attribution?.node ? new WeakRef(attribution.node) : undefined, | |
time: elapsed(viewStart, entry.startTime), | |
biggestShift = { | |
target: attribution?.node ? new WeakRef(attribution.node) : undefined, | |
time: elapsed(viewStart, entry.startTime), | |
previousRect: attribution?.previousRect, | |
currentRect: attribution?.currentRect, | |
devicePixelRatio: window.devicePixelRatio, |
Motivation
Implementation of small adjustments in Browser SDK for CLS attribution:
Include
devicePixelRatio
attribute:prevRect
andcurrentRect
.Adapt fix “most shifted“ element calculation:
Changes
devicePixelRatio
in the CLS attributionTesting
I have gone over the contributing documentation.