Skip to content

Commit 584596d

Browse files
DellaBittaprameshj
authored andcommitted
[Heartbeat Service] Guard against empty heartbeat caches. (#7749)
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.
1 parent d491c11 commit 584596d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.changeset/chilly-emus-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/app': patch
3+
---
4+
5+
App - provide a more robust check to cover more cases of empty heartbeat data.

packages/app/src/heartbeatService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class HeartbeatServiceImpl implements HeartbeatService {
8888
// service, not the browser user agent.
8989
const agent = platformLogger.getPlatformInfoString();
9090
const date = getUTCDateString();
91-
if (this._heartbeatsCache === null) {
91+
if (this._heartbeatsCache?.heartbeats == null) {
9292
this._heartbeatsCache = await this._heartbeatsCachePromise;
9393
}
9494
// Do not store a heartbeat if one is already stored for this day
@@ -128,7 +128,7 @@ export class HeartbeatServiceImpl implements HeartbeatService {
128128
}
129129
// If it's still null or the array is empty, there is no data to send.
130130
if (
131-
this._heartbeatsCache === null ||
131+
this._heartbeatsCache?.heartbeats == null ||
132132
this._heartbeatsCache.heartbeats.length === 0
133133
) {
134134
return '';

0 commit comments

Comments
 (0)