@@ -58,11 +58,6 @@ interface LayoutShiftAttribution {
58
58
currentRect : DOMRectReadOnly ;
59
59
}
60
60
61
- interface Attribution {
62
- value : number ;
63
- nodeIds ?: number [ ] ;
64
- }
65
-
66
61
/**
67
62
* Handler creater for web vitals
68
63
*/
@@ -206,7 +201,7 @@ function isLayoutShift(entry: PerformanceEntry): entry is LayoutShift {
206
201
* Add a CLS event to the replay based on a CLS metric.
207
202
*/
208
203
export function getCumulativeLayoutShift ( metric : Metric ) : ReplayPerformanceEntry < WebVitalData > {
209
- const layoutShifts : Attribution [ ] = [ ] ;
204
+ const layoutShifts : WebVitalData [ 'attributions' ] = [ ] ;
210
205
const nodes : Node [ ] = [ ] ;
211
206
for ( const entry of metric . entries ) {
212
207
if ( isLayoutShift ( entry ) ) {
@@ -220,9 +215,10 @@ export function getCumulativeLayoutShift(metric: Metric): ReplayPerformanceEntry
220
215
}
221
216
}
222
217
}
223
- layoutShifts . push ( { value : entry . value , nodeIds } ) ;
218
+ layoutShifts . push ( { value : entry . value , nodeIds : nodeIds . length ? nodeIds : undefined } ) ;
224
219
}
225
220
}
221
+
226
222
return getWebVital ( metric , 'cumulative-layout-shift' , nodes , layoutShifts ) ;
227
223
}
228
224
@@ -251,14 +247,14 @@ function getWebVital(
251
247
metric : Metric ,
252
248
name : string ,
253
249
nodes : Node [ ] | undefined ,
254
- attributions ?: Attribution [ ] ,
250
+ attributions ?: WebVitalData [ 'attributions' ] ,
255
251
) : ReplayPerformanceEntry < WebVitalData > {
256
252
const value = metric . value ;
257
253
const rating = metric . rating ;
258
254
259
255
const end = getAbsoluteTime ( value ) ;
260
256
261
- const data : ReplayPerformanceEntry < WebVitalData > = {
257
+ return {
262
258
type : 'web-vital' ,
263
259
name,
264
260
start : end ,
@@ -271,6 +267,4 @@ function getWebVital(
271
267
attributions,
272
268
} ,
273
269
} ;
274
-
275
- return data ;
276
270
}
0 commit comments