Skip to content

Commit

Permalink
fix: Frontend crash if IndexedDB is not available, i.e. in Firefox pr…
Browse files Browse the repository at this point in the history
…ivate mode (#29453)

Co-authored-by: Gabriel Casals <83978645+casalsgh@users.noreply.github.com>
  • Loading branch information
crycode-de and casalsgh committed Jun 14, 2023
1 parent 9b89995 commit cb0a92e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/silly-stingrays-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

fix: Frontend crash if IndexedDB is not available, i.e. in Firefox private mode
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class CachedCollection<T extends { _id: string }, U = T> extends Emitter<
}

private async loadFromCache() {
const data = await localforage.getItem<{ version: number; token: unknown; records: unknown[]; updatedAt: Date }>(this.name);
const data = await localforage.getItem<{ version: number; token: unknown; records: unknown[]; updatedAt: Date | string }>(this.name);

if (!data) {
return false;
Expand All @@ -107,6 +107,11 @@ export class CachedCollection<T extends { _id: string }, U = T> extends Emitter<
return false;
}

// updatedAt may be a Date or a string depending on the used localForage backend
if (!(data.updatedAt instanceof Date)) {
data.updatedAt = new Date(data.updatedAt);
}

if (Date.now() - data.updatedAt.getTime() >= 1000 * CachedCollection.MAX_CACHE_TIME) {
return false;
}
Expand Down

0 comments on commit cb0a92e

Please sign in to comment.