@@ -111,7 +111,7 @@ export default class Recorder {
111
111
* `_isReady` is `true`. The emit callback always pushes the triggering event
112
112
* after any buffer reset, ensuring the active buffer has at least one event.
113
113
*
114
- * @returns {BufferCursor } Buffer index and event offset.
114
+ * @returns {BufferCursor } Buffer slot and event exclusive offset.
115
115
*/
116
116
bufferCursor ( ) {
117
117
return {
@@ -181,7 +181,8 @@ export default class Recorder {
181
181
}
182
182
183
183
if ( isCheckout && event . type === EventType . Meta ) {
184
- this . _buffers [ ( this . _currentSlot = this . _previousSlot ) ] = [ ] ;
184
+ this . _currentSlot = this . _previousSlot ;
185
+ this . _buffers [ this . _currentSlot ] = [ ] ;
185
186
}
186
187
187
188
this . _buffers [ this . _currentSlot ] . push ( event ) ;
@@ -218,7 +219,8 @@ export default class Recorder {
218
219
}
219
220
220
221
/**
221
- * Collects all events from both buffers.
222
+ * Collects all events (previous ⊕ current) and returns a new array with a
223
+ * trailing `replay.end` marker.
222
224
*
223
225
* @returns {Array } All events with replay.end marker
224
226
* @private
@@ -236,24 +238,26 @@ export default class Recorder {
236
238
}
237
239
238
240
/**
239
- * Collects events after a cursor position.
241
+ * Collects events strictly after `cursor` (exclusive) and returns a new
242
+ * array with `replay.end`.
240
243
*
241
244
* @param {BufferCursor } cursor - Cursor position to collect from
242
245
* @returns {Array } Events after cursor with replay.end marker
243
246
* @private
244
247
*/
245
248
_collectEventsFromCursor ( cursor ) {
249
+ const currentSlot = this . _currentSlot ;
246
250
const capturedBuffer = this . _buffers [ cursor . slot ] ?? [ ] ;
251
+ const currentBuffer = this . _buffers [ currentSlot ] ;
247
252
const head = capturedBuffer . slice ( Math . max ( 0 , cursor . offset + 1 ) ) ;
248
- const tail =
249
- cursor . slot === this . _currentSlot ? [ ] : this . _buffers [ this . _currentSlot ] ;
253
+ const tail = cursor . slot === currentSlot ? [ ] : currentBuffer ;
250
254
251
255
const events = head . concat ( tail ) ;
252
256
253
- if ( cursor . slot !== this . _currentSlot && head . length === 0 ) {
254
- logger . warn (
255
- 'Leading replay: captured buffer cleared by multiple checkouts',
256
- ) ;
257
+ if ( this . options . debug ?. logErrors ) {
258
+ if ( cursor . slot !== currentSlot && head . length === 0 ) {
259
+ logger . warn ( 'Captured lead buffer cleared by multiple checkouts') ;
260
+ }
257
261
}
258
262
259
263
if ( events . length > 0 ) {
0 commit comments