Skip to content

Commit

Permalink
fix: fixes buffering for legacy destinations (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscb authored Apr 12, 2024
1 parent fd09fbc commit e3f3bee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/three-turkeys-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': patch
---

fix: fixes buffering for legacy destinations
7 changes: 6 additions & 1 deletion packages/browser/src/plugins/ajs-destination/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e3f3bee

Please sign in to comment.