Skip to content

Commit d6a5f05

Browse files
committed
add comments
1 parent 753f35a commit d6a5f05

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/replay/src/replay.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,9 @@ export class ReplayContainer implements ReplayContainerInterface {
833833
// Always increment segmentId regardless of outcome of sending replay
834834
const segmentId = this.session.segmentId++;
835835

836-
// Write to local storage before flushing, in case flush request never starts
836+
// Write to local storage before flushing, in case flush request never starts.
837+
// Ensure that this happens before *any* `await` happens, otherwise we
838+
// will lose data.
837839
setFlushState(FlushState.START, {
838840
events: this.eventBuffer.pendingEvents,
839841
replayId,
@@ -843,9 +845,13 @@ export class ReplayContainer implements ReplayContainerInterface {
843845
timestamp: new Date().getTime(),
844846
});
845847

846-
// Save session (new segment id) after we save flush data assuming
848+
// Save session (new segment id) after we save flush data assuming either
849+
// 1) request succeeds or 2) it fails or never happens, in which case we
850+
// need to retry this segment.
847851
this._maybeSaveSession();
848852

853+
// NOTE: Be mindful that nothing after this point (the first `await`)
854+
// will run after when the page is unloaded.
849855
const [, , recordingData] = await Promise.all(promises);
850856

851857
const sendReplayPromise = this.sendReplay({

0 commit comments

Comments
 (0)