Skip to content

Commit 756f716

Browse files
committed
remove shouldFinalFlush
1 parent 45996ed commit 756f716

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

packages/replay/src/replay.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
PopEventContext,
2020
RecordingOptions,
2121
ReplayContainer as ReplayContainerInterface,
22+
ReplayFlushOptions,
2223
ReplayPluginOptions,
2324
Session,
2425
Timeouts,
@@ -86,11 +87,6 @@ export class ReplayContainer implements ReplayContainerInterface {
8687
*/
8788
private _isEnabled: boolean = false;
8889

89-
/**
90-
* If true, will flush regardless of `_isEnabled` property
91-
*/
92-
private _shouldFinalFlush: boolean = false;
93-
9490
/**
9591
* Paused is a state where:
9692
* - DOM Recording is not listening at all
@@ -259,16 +255,16 @@ export class ReplayContainer implements ReplayContainerInterface {
259255
log(msg);
260256
}
261257

262-
// Set this property so that it ignores `_isEnabled` = false
263258
// We can't move `_isEnabled` after awaiting a flush, otherwise we can
264259
// enter into an infinite loop when `stop()` is called while flushing.
265-
this._shouldFinalFlush = true;
266260
this._isEnabled = false;
267261
this._removeListeners();
268262
this.stopRecording();
269263

270-
// Flush event buffer before stopping
271-
await this.flushImmediate();
264+
this._debouncedFlush.cancel();
265+
// See comment above re: `_isEnabled`, we "force" a flush, ignoring the
266+
// `_isEnabled` state of the plugin since it was disabled above.
267+
await this._flush({force: true})
272268

273269
// After flush, destroy event buffer
274270
this.eventBuffer && this.eventBuffer.destroy();
@@ -279,8 +275,6 @@ export class ReplayContainer implements ReplayContainerInterface {
279275
clearSession(this);
280276
} catch (err) {
281277
this._handleException(err);
282-
} finally {
283-
this._shouldFinalFlush = false;
284278
}
285279
}
286280

@@ -794,8 +788,8 @@ export class ReplayContainer implements ReplayContainerInterface {
794788
* Flush recording data to Sentry. Creates a lock so that only a single flush
795789
* can be active at a time. Do not call this directly.
796790
*/
797-
private _flush: () => Promise<void> = async () => {
798-
if (!this._isEnabled && !this._shouldFinalFlush) {
791+
private _flush = async ({force = false}: ReplayFlushOptions = {}): Promise<void> => {
792+
if (!this._isEnabled && !force) {
799793
// This can happen if e.g. the replay was stopped because of exceeding the retry limit
800794
return;
801795
}

packages/replay/src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,15 @@ export interface ReplayContainer {
451451
setInitialState(): void;
452452
}
453453

454+
export interface ReplayFlushOptions {
455+
/**
456+
* If true, flush while ignoring the `_isEnabled` state of
457+
* Replay integration. (By default, flush is noop if integration
458+
* is stopped).
459+
*/
460+
force?: boolean;
461+
}
462+
454463
export interface ReplayPerformanceEntry<T> {
455464
/**
456465
* One of these types https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType

0 commit comments

Comments
 (0)