From e3f3bee5831abbe9b3005f77266f72ccda65f9e6 Mon Sep 17 00:00:00 2001 From: Oscar Bazaldua <511911+oscb@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:23:15 -0700 Subject: [PATCH] fix: fixes buffering for legacy destinations (#1067) --- .changeset/three-turkeys-talk.md | 5 +++++ packages/browser/src/plugins/ajs-destination/index.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/three-turkeys-talk.md diff --git a/.changeset/three-turkeys-talk.md b/.changeset/three-turkeys-talk.md new file mode 100644 index 000000000..031b690bd --- /dev/null +++ b/.changeset/three-turkeys-talk.md @@ -0,0 +1,5 @@ +--- +'@segment/analytics-next': patch +--- + +fix: fixes buffering for legacy destinations diff --git a/packages/browser/src/plugins/ajs-destination/index.ts b/packages/browser/src/plugins/ajs-destination/index.ts index d2354e1de..80cd0dad0 100644 --- a/packages/browser/src/plugins/ajs-destination/index.ts +++ b/packages/browser/src/plugins/ajs-destination/index.ts @@ -192,7 +192,7 @@ export class LegacyDestination implements InternalPluginWithAddMiddleware { return ( // page events can't be buffered because of destinations that automatically add page views ctx.event.type !== 'page' && - (isOffline() || this._ready === false || this._initialized === false) + (isOffline() || this._ready !== true || this._initialized !== true) ) } @@ -313,6 +313,11 @@ export class LegacyDestination implements InternalPluginWithAddMiddleware { // eslint-disable-next-line @typescript-eslint/no-misused-promises setTimeout(async () => { + if (isOffline() || this._ready !== true || this._initialized !== true) { + this.scheduleFlush() + return + } + this.flushing = true this.buffer = await flushQueue(this, this.buffer) this.flushing = false