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