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