Skip to content

Commit 2542736

Browse files
authored
Minor cleanup for lead replay feature (#1342)
1 parent b3aeddc commit 2542736

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/browser/replay/recorder.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default class Recorder {
111111
* `_isReady` is `true`. The emit callback always pushes the triggering event
112112
* after any buffer reset, ensuring the active buffer has at least one event.
113113
*
114-
* @returns {BufferCursor} Buffer index and event offset.
114+
* @returns {BufferCursor} Buffer slot and event exclusive offset.
115115
*/
116116
bufferCursor() {
117117
return {
@@ -181,7 +181,8 @@ export default class Recorder {
181181
}
182182

183183
if (isCheckout && event.type === EventType.Meta) {
184-
this._buffers[(this._currentSlot = this._previousSlot)] = [];
184+
this._currentSlot = this._previousSlot;
185+
this._buffers[this._currentSlot] = [];
185186
}
186187

187188
this._buffers[this._currentSlot].push(event);
@@ -218,7 +219,8 @@ export default class Recorder {
218219
}
219220

220221
/**
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.
222224
*
223225
* @returns {Array} All events with replay.end marker
224226
* @private
@@ -236,24 +238,26 @@ export default class Recorder {
236238
}
237239

238240
/**
239-
* Collects events after a cursor position.
241+
* Collects events strictly after `cursor` (exclusive) and returns a new
242+
* array with `replay.end`.
240243
*
241244
* @param {BufferCursor} cursor - Cursor position to collect from
242245
* @returns {Array} Events after cursor with replay.end marker
243246
* @private
244247
*/
245248
_collectEventsFromCursor(cursor) {
249+
const currentSlot = this._currentSlot;
246250
const capturedBuffer = this._buffers[cursor.slot] ?? [];
251+
const currentBuffer = this._buffers[currentSlot];
247252
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;
250254

251255
const events = head.concat(tail);
252256

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+
}
257261
}
258262

259263
if (events.length > 0) {

0 commit comments

Comments
 (0)