Skip to content

Commit 6235b5b

Browse files
committed
ref: Always wait for worker to be loaded
1 parent 84a73d6 commit 6235b5b

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

packages/replay/src/eventBuffer/EventBufferProxy.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ export class EventBufferProxy implements EventBuffer {
4949
}
5050

5151
/** @inheritDoc */
52-
public finish(): Promise<ReplayRecordingData> {
52+
public async finish(): Promise<ReplayRecordingData> {
53+
// Ensure the worker is loaded, so the sent event is compressed
54+
try {
55+
await this.ensureWorkerIsLoaded();
56+
} catch (error) {
57+
// If this fails, we'll just send uncompressed events
58+
}
59+
5360
return this._used.finish();
5461
}
5562

packages/replay/src/replay.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from './constants';
1515
import { setupPerformanceObserver } from './coreHandlers/performanceObserver';
1616
import { createEventBuffer } from './eventBuffer';
17-
import { EventBufferProxy } from './eventBuffer/EventBufferProxy';
1817
import { getSession } from './session/getSession';
1918
import { saveSession } from './session/saveSession';
2019
import type {
@@ -330,18 +329,9 @@ export class ReplayContainer implements ReplayContainerInterface {
330329
* from calling both `flush` and `_debouncedFlush`. Otherwise, there could be
331330
* cases of mulitple flushes happening closely together.
332331
*/
333-
public async flushImmediate(waitForCompression?: boolean): Promise<void> {
332+
public flushImmediate(): Promise<void> {
334333
this._debouncedFlush();
335334
// `.flush` is provided by the debounced function, analogously to lodash.debounce
336-
337-
// Ensure the worker is loaded, so the sent event is compressed
338-
if (waitForCompression && this.eventBuffer instanceof EventBufferProxy) {
339-
try {
340-
await this.eventBuffer.ensureWorkerIsLoaded();
341-
} catch (error) {
342-
// If this fails, we'll just send uncompressed events
343-
}
344-
}
345335
return this._debouncedFlush.flush() as Promise<void>;
346336
}
347337

@@ -553,7 +543,7 @@ export class ReplayContainer implements ReplayContainerInterface {
553543
// filtered on the UI.
554544
if (this.recordingMode === 'session') {
555545
// We want to ensure the worker is ready, as otherwise we'd always send the first event uncompressed
556-
void this.flushImmediate(true);
546+
void this.flushImmediate();
557547
}
558548

559549
return true;

0 commit comments

Comments
 (0)