Skip to content

Commit e9ff107

Browse files
authored
[Heartbeat Service] More null service protections added to triggerHeartBeat (#7789)
Users are reporting furhter issues with the heartbeat service returning a null cache on Opera. There's a case in `triggerHeartBeat` which the code assumes that the cache was created properly. Add a check to ensure that the cache exists, and if not, returns immediately.
1 parent a5c1a35 commit e9ff107

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/fast-moose-approve.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/app': patch
3+
---
4+
5+
More safeguards to ensure that heartbeat objects queried from IndexedDB include a heartbeats field.

packages/app/src/heartbeatService.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export class HeartbeatServiceImpl implements HeartbeatService {
9090
const date = getUTCDateString();
9191
if (this._heartbeatsCache?.heartbeats == null) {
9292
this._heartbeatsCache = await this._heartbeatsCachePromise;
93+
// If we failed to construct a heartbeats cache, then return immediately.
94+
if (this._heartbeatsCache?.heartbeats == null) {
95+
return;
96+
}
9397
}
9498
// Do not store a heartbeat if one is already stored for this day
9599
// or if a header has already been sent today.
@@ -236,7 +240,11 @@ export class HeartbeatStorageImpl implements HeartbeatStorage {
236240
return { heartbeats: [] };
237241
} else {
238242
const idbHeartbeatObject = await readHeartbeatsFromIndexedDB(this.app);
239-
return idbHeartbeatObject || { heartbeats: [] };
243+
if (idbHeartbeatObject?.heartbeats) {
244+
return idbHeartbeatObject;
245+
} else {
246+
return { heartbeats: [] };
247+
}
240248
}
241249
}
242250
// overwrite the storage with the provided heartbeats

0 commit comments

Comments
 (0)