Skip to content

Commit

Permalink
[Heartbeat Service] Guard against empty heartbeat caches. (#7749)
Browse files Browse the repository at this point in the history
There seems to be a potential scenario in the heartbeat service running in the Opera browser (#7736) that the heartbeatCache exists but it's an empty object. The code implementation encounters errors in these cases as it assumes the heartbeatCache has a heartbeats array. This change better detects these empty object cases and treats them in a similar way as if there's nothing in the heartbeatCache.
  • Loading branch information
DellaBitta authored Nov 7, 2023
1 parent 5f496e4 commit 5c7fa84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-emus-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/app': patch
---

App - provide a more robust check to cover more cases of empty heartbeat data.
4 changes: 2 additions & 2 deletions packages/app/src/heartbeatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class HeartbeatServiceImpl implements HeartbeatService {
// service, not the browser user agent.
const agent = platformLogger.getPlatformInfoString();
const date = getUTCDateString();
if (this._heartbeatsCache === null) {
if (this._heartbeatsCache?.heartbeats == null) {
this._heartbeatsCache = await this._heartbeatsCachePromise;
}
// Do not store a heartbeat if one is already stored for this day
Expand Down Expand Up @@ -128,7 +128,7 @@ export class HeartbeatServiceImpl implements HeartbeatService {
}
// If it's still null or the array is empty, there is no data to send.
if (
this._heartbeatsCache === null ||
this._heartbeatsCache?.heartbeats == null ||
this._heartbeatsCache.heartbeats.length === 0
) {
return '';
Expand Down

0 comments on commit 5c7fa84

Please sign in to comment.