Skip to content

Commit

Permalink
[Heartbeat Service] More null service protections added to triggerHea…
Browse files Browse the repository at this point in the history
…rtBeat (#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.
  • Loading branch information
DellaBitta committed Nov 22, 2023
1 parent a5c1a35 commit e9ff107
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fast-moose-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/app': patch
---

More safeguards to ensure that heartbeat objects queried from IndexedDB include a heartbeats field.
10 changes: 9 additions & 1 deletion packages/app/src/heartbeatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export class HeartbeatServiceImpl implements HeartbeatService {
const date = getUTCDateString();
if (this._heartbeatsCache?.heartbeats == null) {
this._heartbeatsCache = await this._heartbeatsCachePromise;
// If we failed to construct a heartbeats cache, then return immediately.
if (this._heartbeatsCache?.heartbeats == null) {
return;
}
}
// Do not store a heartbeat if one is already stored for this day
// or if a header has already been sent today.
Expand Down Expand Up @@ -236,7 +240,11 @@ export class HeartbeatStorageImpl implements HeartbeatStorage {
return { heartbeats: [] };
} else {
const idbHeartbeatObject = await readHeartbeatsFromIndexedDB(this.app);
return idbHeartbeatObject || { heartbeats: [] };
if (idbHeartbeatObject?.heartbeats) {
return idbHeartbeatObject;
} else {
return { heartbeats: [] };
}
}
}
// overwrite the storage with the provided heartbeats
Expand Down

0 comments on commit e9ff107

Please sign in to comment.