@@ -183,30 +183,34 @@ function createResourceEntry(
183
183
*/
184
184
export function getLargestContentfulPaint ( metric : Metric ) : ReplayPerformanceEntry < WebVitalData > {
185
185
const lastEntry = metric . entries [ metric . entries . length - 1 ] as ( PerformanceEntry & { element ?: Node } ) | undefined ;
186
- const node = lastEntry ? lastEntry . element : undefined ;
186
+ const node = lastEntry && lastEntry . element ? [ lastEntry . element ] : undefined ;
187
187
return getWebVital ( metric , 'largest-contentful-paint' , node ) ;
188
188
}
189
189
190
190
/**
191
191
* Add a CLS event to the replay based on a CLS metric.
192
192
*/
193
193
export function getCumulativeLayoutShift ( metric : Metric ) : ReplayPerformanceEntry < WebVitalData > {
194
- // get first node that shifts
195
- const firstEntry = metric . entries [ 0 ] as ( PerformanceEntry & { sources ?: LayoutShiftAttribution [ ] } ) | undefined ;
196
- const node = firstEntry
197
- ? firstEntry . sources && firstEntry . sources [ 0 ]
198
- ? firstEntry . sources [ 0 ] . node
199
- : undefined
200
- : undefined ;
201
- return getWebVital ( metric , 'cumulative-layout-shift' , node ) ;
194
+ const lastEntry = metric . entries [ metric . entries . length - 1 ] as
195
+ | ( PerformanceEntry & { sources ?: LayoutShiftAttribution [ ] } )
196
+ | undefined ;
197
+ const nodes : Node [ ] = [ ] ;
198
+ if ( lastEntry && lastEntry . sources ) {
199
+ for ( const source of lastEntry . sources ) {
200
+ if ( source . node ) {
201
+ nodes . push ( source . node ) ;
202
+ }
203
+ }
204
+ }
205
+ return getWebVital ( metric , 'cumulative-layout-shift' , nodes ) ;
202
206
}
203
207
204
208
/**
205
209
* Add a FID event to the replay based on a FID metric.
206
210
*/
207
211
export function getFirstInputDelay ( metric : Metric ) : ReplayPerformanceEntry < WebVitalData > {
208
212
const lastEntry = metric . entries [ metric . entries . length - 1 ] as ( PerformanceEntry & { target ?: Node } ) | undefined ;
209
- const node = lastEntry ? lastEntry . target : undefined ;
213
+ const node = lastEntry && lastEntry . target ? [ lastEntry . target ] : undefined ;
210
214
return getWebVital ( metric , 'first-input-delay' , node ) ;
211
215
}
212
216
@@ -215,18 +219,14 @@ export function getFirstInputDelay(metric: Metric): ReplayPerformanceEntry<WebVi
215
219
*/
216
220
export function getInteractionToNextPaint ( metric : Metric ) : ReplayPerformanceEntry < WebVitalData > {
217
221
const lastEntry = metric . entries [ metric . entries . length - 1 ] as ( PerformanceEntry & { target ?: Node } ) | undefined ;
218
- const node = lastEntry ? lastEntry . target : undefined ;
222
+ const node = lastEntry && lastEntry . target ? [ lastEntry . target ] : undefined ;
219
223
return getWebVital ( metric , 'interaction-to-next-paint' , node ) ;
220
224
}
221
225
222
226
/**
223
227
* Add an web vital event to the replay based on the web vital metric.
224
228
*/
225
- export function getWebVital (
226
- metric : Metric ,
227
- name : string ,
228
- node : Node | undefined ,
229
- ) : ReplayPerformanceEntry < WebVitalData > {
229
+ function getWebVital ( metric : Metric , name : string , nodes : Node [ ] | undefined ) : ReplayPerformanceEntry < WebVitalData > {
230
230
const value = metric . value ;
231
231
const rating = metric . rating ;
232
232
@@ -241,7 +241,7 @@ export function getWebVital(
241
241
value,
242
242
size : value ,
243
243
rating,
244
- nodeId : node ? record . mirror . getId ( node ) : undefined ,
244
+ nodeIds : nodes ? nodes . map ( node => record . mirror . getId ( node ) ) : undefined ,
245
245
} ,
246
246
} ;
247
247
0 commit comments