Skip to content

Commit c95d058

Browse files
authored
fix(metrics): Check for cls entry sources (#3775)
The LayoutShift.sources field may not exist in certain browsers, even if the LayoutShift API is there. This PR patches logic that adds CLS data to make sure that `._clsEntry.sources` exists. Ref: https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift
1 parent ab0bc93 commit c95d058

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/tracing/src/browser/metrics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ export class MetricsInstrumentation {
214214
transaction.setTag('lcp.size', this._lcpEntry.size);
215215
}
216216

217-
if (this._clsEntry) {
217+
// See: https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift
218+
if (this._clsEntry && this._clsEntry.sources) {
218219
logger.log('[Measurements] Adding CLS Data');
219220
this._clsEntry.sources.map((source, index) =>
220221
transaction.setTag(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),

0 commit comments

Comments
 (0)