Repository navigation
fix(analytics-core): flush heartbeat events before awaiting delivery - #2199
Open
daniel-graham-amplitude wants to merge 1 commit into
Open
daniel-graham-amplitude wants to merge 1 commit into
daniel-graham-amplitude wants to merge 1 commit into
Conversation
Contributor
size-limit report 📦
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Start the heartbeat client flush immediately after queueing events. On ordinary
pagehide, the video capture finalizes the active play asuntracked. Awaiting delivery before starting the flush could leave that event in the destination queue when the browser discarded the document.Preserve the existing back-forward-cache behavior. A persisted
pagehidekeeps the video observer and play session alive across restoration.Related to SDK-723 and the corpsite reproduction.
Validation
untrackedstop beacon on ordinary Back and continuity of the observer and play across cached Back/Forward.pnpm test:examplesis blocked on the base branch becausejest.setup.examples.jsis missing.Checklist
Note
Medium Risk
Changes page-unload send timing in a core analytics path; impact is scoped to ordering of flush vs. await but affects reliability-critical lifecycle behavior.
Overview
heartbeat()now triggersclient.flush()as soon as events are queued for send, instead of waiting for everytrackpromise to finish first.When
flushClientis true (e.g. non-persistedpagehide), delivery starts immediately while track promises can still be pending until the flush completes. That avoids losing final snapshots—such as videountrackedstop beacons—when the browser tears down the page before the destination queue drains.The unit test was tightened to assert
trackthenflushordering using a track promise that only resolves when flush runs.Reviewed by Cursor Bugbot for commit db6ba32. Bugbot is set up for automated code reviews on this repo. Configure here.