@@ -231,8 +231,8 @@ export class ReplayContainer implements ReplayContainerInterface {
231231      __DEBUG_BUILD__  &&  logger . log ( '[Replay] Stopping Replays' ) ; 
232232      this . _isEnabled  =  false ; 
233233      this . _removeListeners ( ) ; 
234-       this . _stopRecording ?. ( ) ; 
235-       this . eventBuffer ? .destroy ( ) ; 
234+       this . _stopRecording   &&   this . _stopRecording ( ) ; 
235+       this . eventBuffer   &&   this . eventBuffer . destroy ( ) ; 
236236      this . eventBuffer  =  null ; 
237237    }  catch  ( err )  { 
238238      this . _handleException ( err ) ; 
@@ -277,7 +277,7 @@ export class ReplayContainer implements ReplayContainerInterface {
277277   */ 
278278  public  addUpdate ( cb : AddUpdateCallback ) : void { 
279279    // We need to always run `cb` (e.g. in the case of `this.recordingMode == 'error'`) 
280-     const  cbResult  =  cb ?. ( ) ; 
280+     const  cbResult  =  cb ( ) ; 
281281
282282    // If this option is turned on then we will only want to call `flush` 
283283    // explicitly 
@@ -334,6 +334,11 @@ export class ReplayContainer implements ReplayContainerInterface {
334334    return  this . _debouncedFlush . flush ( )  as  Promise < void > ; 
335335  } 
336336
337+   /** Get the current sesion (=replay) ID */ 
338+   public  getSessionId ( ) : string  |  undefined  { 
339+     return  this . session  &&  this . session . id ; 
340+   } 
341+ 
337342  /** A wrapper to conditionally capture exceptions. */ 
338343  private  _handleException ( error : unknown ) : void { 
339344    __DEBUG_BUILD__  &&  logger . error ( '[Replay]' ,  error ) ; 
@@ -362,8 +367,9 @@ export class ReplayContainer implements ReplayContainerInterface {
362367      this . _setInitialState ( ) ; 
363368    } 
364369
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 ; 
367373    } 
368374
369375    this . session  =  session ; 
@@ -404,7 +410,9 @@ export class ReplayContainer implements ReplayContainerInterface {
404410      if  ( ! this . _hasInitializedCoreListeners )  { 
405411        // Listeners from core SDK // 
406412        const  scope  =  getCurrentHub ( ) . getScope ( ) ; 
407-         scope ?. addScopeListener ( this . _handleCoreBreadcrumbListener ( 'scope' ) ) ; 
413+         if  ( scope )  { 
414+           scope . addScopeListener ( this . _handleCoreBreadcrumbListener ( 'scope' ) ) ; 
415+         } 
408416        addInstrumentationHandler ( 'dom' ,  this . _handleCoreBreadcrumbListener ( 'dom' ) ) ; 
409417        addInstrumentationHandler ( 'fetch' ,  handleFetchSpanListener ( this ) ) ; 
410418        addInstrumentationHandler ( 'xhr' ,  handleXhrSpanListener ( this ) ) ; 
@@ -491,7 +499,7 @@ export class ReplayContainer implements ReplayContainerInterface {
491499      // of the previous session. Do not immediately flush in this case 
492500      // to avoid capturing only the checkout and instead the replay will 
493501      // be captured if they perform any follow-up actions. 
494-       if  ( this . session ? .previousSessionId )  { 
502+       if  ( this . session   &&   this . session . previousSessionId )  { 
495503        return  true ; 
496504      } 
497505
@@ -706,7 +714,7 @@ export class ReplayContainer implements ReplayContainerInterface {
706714   * Returns true if session is not expired, false otherwise. 
707715   */ 
708716  private  _checkAndHandleExpiredSession ( {  expiry =  SESSION_IDLE_DURATION  } : {  expiry ?: number  }  =  { } ) : boolean  |  void { 
709-     const  oldSessionId  =  this . session ?. id ; 
717+     const  oldSessionId  =  this . getSessionId ( ) ; 
710718
711719    // Prevent starting a new session if the last user activity is older than 
712720    // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new 
@@ -723,7 +731,7 @@ export class ReplayContainer implements ReplayContainerInterface {
723731    this . _loadSession ( {  expiry } ) ; 
724732
725733    // Session was expired if session ids do not match 
726-     const  expired  =  oldSessionId  !==  this . session ?. id ; 
734+     const  expired  =  oldSessionId  !==  this . getSessionId ( ) ; 
727735
728736    if  ( ! expired )  { 
729737      return  true ; 
@@ -787,14 +795,14 @@ export class ReplayContainer implements ReplayContainerInterface {
787795   * Should never be called directly, only by `flush` 
788796   */ 
789797  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.' ) ; 
792800      return ; 
793801    } 
794802
795803    await  this . _addPerformanceEntries ( ) ; 
796804
797-     if  ( ! this . eventBuffer ? .pendingLength )  { 
805+     if  ( ! this . eventBuffer . pendingLength )  { 
798806      return ; 
799807    } 
800808
@@ -847,13 +855,13 @@ export class ReplayContainer implements ReplayContainerInterface {
847855      return ; 
848856    } 
849857
850-     if  ( ! this . session ?. id )  { 
858+     if  ( ! this . session )  { 
851859      __DEBUG_BUILD__  &&  logger . error ( '[Replay] No session found to flush.' ) ; 
852860      return ; 
853861    } 
854862
855863    // A flush is about to happen, cancel any queued flushes 
856-     this . _debouncedFlush ? .cancel ( ) ; 
864+     this . _debouncedFlush . cancel ( ) ; 
857865
858866    // this._flushLock acts as a lock so that future calls to `_flush()` 
859867    // will be blocked until this promise resolves 
0 commit comments