@@ -231,8 +231,8 @@ export class ReplayContainer implements ReplayContainerInterface {
231
231
__DEBUG_BUILD__ && logger . log ( '[Replay] Stopping Replays' ) ;
232
232
this . _isEnabled = false ;
233
233
this . _removeListeners ( ) ;
234
- this . _stopRecording ?. ( ) ;
235
- this . eventBuffer ? .destroy ( ) ;
234
+ this . _stopRecording && this . _stopRecording ( ) ;
235
+ this . eventBuffer && this . eventBuffer . destroy ( ) ;
236
236
this . eventBuffer = null ;
237
237
} catch ( err ) {
238
238
this . _handleException ( err ) ;
@@ -277,7 +277,7 @@ export class ReplayContainer implements ReplayContainerInterface {
277
277
*/
278
278
public addUpdate ( cb : AddUpdateCallback ) : void {
279
279
// We need to always run `cb` (e.g. in the case of `this.recordingMode == 'error'`)
280
- const cbResult = cb ?. ( ) ;
280
+ const cbResult = cb ( ) ;
281
281
282
282
// If this option is turned on then we will only want to call `flush`
283
283
// explicitly
@@ -334,6 +334,11 @@ export class ReplayContainer implements ReplayContainerInterface {
334
334
return this . _debouncedFlush . flush ( ) as Promise < void > ;
335
335
}
336
336
337
+ /** Get the current sesion (=replay) ID */
338
+ public getSessionId ( ) : string | undefined {
339
+ return this . session && this . session . id ;
340
+ }
341
+
337
342
/** A wrapper to conditionally capture exceptions. */
338
343
private _handleException ( error : unknown ) : void {
339
344
__DEBUG_BUILD__ && logger . error ( '[Replay]' , error ) ;
@@ -362,8 +367,9 @@ export class ReplayContainer implements ReplayContainerInterface {
362
367
this . _setInitialState ( ) ;
363
368
}
364
369
365
- if ( session . id !== this . session ?. id ) {
366
- session . previousSessionId = this . session ?. id ;
370
+ const currentSessionId = this . getSessionId ( ) ;
371
+ if ( session . id !== currentSessionId ) {
372
+ session . previousSessionId = currentSessionId ;
367
373
}
368
374
369
375
this . session = session ;
@@ -404,7 +410,9 @@ export class ReplayContainer implements ReplayContainerInterface {
404
410
if ( ! this . _hasInitializedCoreListeners ) {
405
411
// Listeners from core SDK //
406
412
const scope = getCurrentHub ( ) . getScope ( ) ;
407
- scope ?. addScopeListener ( this . _handleCoreBreadcrumbListener ( 'scope' ) ) ;
413
+ if ( scope ) {
414
+ scope . addScopeListener ( this . _handleCoreBreadcrumbListener ( 'scope' ) ) ;
415
+ }
408
416
addInstrumentationHandler ( 'dom' , this . _handleCoreBreadcrumbListener ( 'dom' ) ) ;
409
417
addInstrumentationHandler ( 'fetch' , handleFetchSpanListener ( this ) ) ;
410
418
addInstrumentationHandler ( 'xhr' , handleXhrSpanListener ( this ) ) ;
@@ -491,7 +499,7 @@ export class ReplayContainer implements ReplayContainerInterface {
491
499
// of the previous session. Do not immediately flush in this case
492
500
// to avoid capturing only the checkout and instead the replay will
493
501
// be captured if they perform any follow-up actions.
494
- if ( this . session ? .previousSessionId ) {
502
+ if ( this . session && this . session . previousSessionId ) {
495
503
return true ;
496
504
}
497
505
@@ -706,7 +714,7 @@ export class ReplayContainer implements ReplayContainerInterface {
706
714
* Returns true if session is not expired, false otherwise.
707
715
*/
708
716
private _checkAndHandleExpiredSession ( { expiry = SESSION_IDLE_DURATION } : { expiry ?: number } = { } ) : boolean | void {
709
- const oldSessionId = this . session ?. id ;
717
+ const oldSessionId = this . getSessionId ( ) ;
710
718
711
719
// Prevent starting a new session if the last user activity is older than
712
720
// MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
@@ -723,7 +731,7 @@ export class ReplayContainer implements ReplayContainerInterface {
723
731
this . _loadSession ( { expiry } ) ;
724
732
725
733
// Session was expired if session ids do not match
726
- const expired = oldSessionId !== this . session ?. id ;
734
+ const expired = oldSessionId !== this . getSessionId ( ) ;
727
735
728
736
if ( ! expired ) {
729
737
return true ;
@@ -787,14 +795,14 @@ export class ReplayContainer implements ReplayContainerInterface {
787
795
* Should never be called directly, only by `flush`
788
796
*/
789
797
private async _runFlush ( ) : Promise < void > {
790
- if ( ! this . session ) {
791
- __DEBUG_BUILD__ && logger . error ( '[Replay] No session found to flush.' ) ;
798
+ if ( ! this . session || ! this . eventBuffer ) {
799
+ __DEBUG_BUILD__ && logger . error ( '[Replay] No session or eventBuffer found to flush.' ) ;
792
800
return ;
793
801
}
794
802
795
803
await this . _addPerformanceEntries ( ) ;
796
804
797
- if ( ! this . eventBuffer ? .pendingLength ) {
805
+ if ( ! this . eventBuffer . pendingLength ) {
798
806
return ;
799
807
}
800
808
@@ -847,13 +855,13 @@ export class ReplayContainer implements ReplayContainerInterface {
847
855
return ;
848
856
}
849
857
850
- if ( ! this . session ?. id ) {
858
+ if ( ! this . session ) {
851
859
__DEBUG_BUILD__ && logger . error ( '[Replay] No session found to flush.' ) ;
852
860
return ;
853
861
}
854
862
855
863
// A flush is about to happen, cancel any queued flushes
856
- this . _debouncedFlush ? .cancel ( ) ;
864
+ this . _debouncedFlush . cancel ( ) ;
857
865
858
866
// this._flushLock acts as a lock so that future calls to `_flush()`
859
867
// will be blocked until this promise resolves
0 commit comments