@@ -13,21 +13,28 @@ type RecordingEmitCallback = (event: RecordingEvent, isCheckout?: boolean) => vo
13
13
* Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
14
14
*/
15
15
export function getHandleRecordingEmit ( replay : ReplayContainer ) : RecordingEmitCallback {
16
- return ( event : RecordingEvent , isCheckout ?: boolean ) => {
16
+ let hadFirstEvent = false ;
17
+
18
+ return ( event : RecordingEvent , _isCheckout ?: boolean ) => {
17
19
// If this is false, it means session is expired, create and a new session and wait for checkout
18
20
if ( ! replay . checkAndHandleExpiredSession ( ) ) {
19
21
__DEBUG_BUILD__ && logger . error ( '[Replay] Received replay event after session expired.' ) ;
20
22
21
23
return ;
22
24
}
23
25
26
+ // `_isCheckout` is only set when the checkout is due to `checkoutEveryNms`
27
+ // We also want to treat the first event as a checkout, so we handle this specifically here
28
+ const isCheckout = _isCheckout || ! hadFirstEvent ;
29
+ hadFirstEvent = true ;
30
+
24
31
replay . addUpdate ( ( ) => {
25
32
// The session is always started immediately on pageload/init, but for
26
33
// error-only replays, it should reflect the most recent checkout
27
34
// when an error occurs. Clear any state that happens before this current
28
35
// checkout. This needs to happen before `addEvent()` which updates state
29
36
// dependent on this reset.
30
- if ( replay . recordingMode === 'error' && event . type === 2 ) {
37
+ if ( replay . recordingMode === 'error' && isCheckout ) {
31
38
replay . setInitialState ( ) ;
32
39
}
33
40
@@ -37,7 +44,7 @@ export function getHandleRecordingEmit(replay: ReplayContainer): RecordingEmitCa
37
44
38
45
// Different behavior for full snapshots (type=2), ignore other event types
39
46
// See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
40
- if ( event . type !== 2 ) {
47
+ if ( ! isCheckout ) {
41
48
return false ;
42
49
}
43
50
0 commit comments