From e9ff107eedbb9ec695ddc35e45bdd62734735674 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 22 Nov 2023 15:16:20 -0500 Subject: [PATCH] [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. --- .changeset/fast-moose-approve.md | 5 +++++ packages/app/src/heartbeatService.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/fast-moose-approve.md diff --git a/.changeset/fast-moose-approve.md b/.changeset/fast-moose-approve.md new file mode 100644 index 00000000000..b5634f9e8d3 --- /dev/null +++ b/.changeset/fast-moose-approve.md @@ -0,0 +1,5 @@ +--- +'@firebase/app': patch +--- + +More safeguards to ensure that heartbeat objects queried from IndexedDB include a heartbeats field. diff --git a/packages/app/src/heartbeatService.ts b/packages/app/src/heartbeatService.ts index 5febd64c550..221c5846c86 100644 --- a/packages/app/src/heartbeatService.ts +++ b/packages/app/src/heartbeatService.ts @@ -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. @@ -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