@@ -58,11 +58,6 @@ interface LayoutShiftAttribution {
5858 currentRect : DOMRectReadOnly ;
5959}
6060
61- interface Attribution {
62- value : number ;
63- nodeIds ?: number [ ] ;
64- }
65-
6661/**
6762 * Handler creater for web vitals
6863 */
@@ -206,7 +201,7 @@ function isLayoutShift(entry: PerformanceEntry): entry is LayoutShift {
206201 * Add a CLS event to the replay based on a CLS metric.
207202 */
208203export function getCumulativeLayoutShift ( metric : Metric ) : ReplayPerformanceEntry < WebVitalData > {
209- const layoutShifts : Attribution [ ] = [ ] ;
204+ const layoutShifts : WebVitalData [ 'attributions' ] = [ ] ;
210205 const nodes : Node [ ] = [ ] ;
211206 for ( const entry of metric . entries ) {
212207 if ( isLayoutShift ( entry ) ) {
@@ -220,9 +215,10 @@ export function getCumulativeLayoutShift(metric: Metric): ReplayPerformanceEntry
220215 }
221216 }
222217 }
223- layoutShifts . push ( { value : entry . value , nodeIds } ) ;
218+ layoutShifts . push ( { value : entry . value , nodeIds : nodeIds . length ? nodeIds : undefined } ) ;
224219 }
225220 }
221+
226222 return getWebVital ( metric , 'cumulative-layout-shift' , nodes , layoutShifts ) ;
227223}
228224
@@ -251,14 +247,14 @@ function getWebVital(
251247 metric : Metric ,
252248 name : string ,
253249 nodes : Node [ ] | undefined ,
254- attributions ?: Attribution [ ] ,
250+ attributions ?: WebVitalData [ 'attributions' ] ,
255251) : ReplayPerformanceEntry < WebVitalData > {
256252 const value = metric . value ;
257253 const rating = metric . rating ;
258254
259255 const end = getAbsoluteTime ( value ) ;
260256
261- const data : ReplayPerformanceEntry < WebVitalData > = {
257+ return {
262258 type : 'web-vital' ,
263259 name,
264260 start : end ,
@@ -271,6 +267,4 @@ function getWebVital(
271267 attributions,
272268 } ,
273269 } ;
274-
275- return data ;
276270}
0 commit comments