File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed
packages/browser-utils/src/metrics Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -209,20 +209,18 @@ export function listenForWebVitalReportEvents(
209209 collectorCallback : ( event : WebVitalReportEvent , pageloadSpanId : string ) => void ,
210210) {
211211 let pageloadSpanId : string | undefined ;
212- let triggeredReportEvent : WebVitalReportEvent | undefined ;
213- let collected = false ;
214212
215- function _runCollectorCallbackOnce ( ) {
216- if ( ! collected && triggeredReportEvent ) {
217- collectorCallback ( triggeredReportEvent , pageloadSpanId ?? 'unknown' ) ;
213+ let collected = false ;
214+ function _runCollectorCallbackOnce ( event : WebVitalReportEvent ) {
215+ if ( ! collected ) {
216+ collectorCallback ( event , pageloadSpanId ?? 'unknown' ) ;
218217 collected = true ;
219218 }
220219 }
221220
222221 onHidden ( ( ) => {
223222 if ( ! collected ) {
224- triggeredReportEvent = 'pagehide' ;
225- _runCollectorCallbackOnce ( ) ;
223+ _runCollectorCallbackOnce ( 'pagehide' ) ;
226224 }
227225 } ) ;
228226
@@ -235,8 +233,7 @@ export function listenForWebVitalReportEvents(
235233 const unsubscribeStartNavigation = client . on ( 'beforeStartNavigationSpan' , ( _ , options ) => {
236234 // we only want to collect LCP if we actually navigate. Redirects should be ignored.
237235 if ( ! options ?. isRedirect ) {
238- triggeredReportEvent = 'navigation' ;
239- _runCollectorCallbackOnce ( ) ;
236+ _runCollectorCallbackOnce ( 'navigation' ) ;
240237 unsubscribeStartNavigation ?.( ) ;
241238 }
242239 } ) ;
You can’t perform that action at this time.
0 commit comments