Skip to content

Commit 5d7b5f7

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

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,9 @@ export class ReplayContainer implements ReplayContainerInterface {
330330
* from calling both `flush` and `_debouncedFlush`. Otherwise, there could be
331331
* cases of mulitple flushes happening closely together.
332332
*/
333-
public async flushImmediate(waitForCompression?: boolean): Promise<void> {
333+
public flushImmediate(): Promise<void> {
334334
this._debouncedFlush();
335335
// `.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-
}
345336
return this._debouncedFlush.flush() as Promise<void>;
346337
}
347338

@@ -553,7 +544,7 @@ export class ReplayContainer implements ReplayContainerInterface {
553544
// filtered on the UI.
554545
if (this.recordingMode === 'session') {
555546
// We want to ensure the worker is ready, as otherwise we'd always send the first event uncompressed
556-
void this.flushImmediate(true);
547+
void this.flushImmediate();
557548
}
558549

559550
return true;

0 commit comments

Comments
 (0)