feat: Conditionally set default history storage to localStorage for improved compatibility.

This commit is contained in:
Danish Arora 2025-11-21 13:52:20 -05:00
parent a0bc652791
commit d320c753cf
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E

View File

@ -31,6 +31,8 @@ type StoredContentMessage = {
}; };
const HISTORY_STORAGE_PREFIX = "waku:sds:history:"; const HISTORY_STORAGE_PREFIX = "waku:sds:history:";
const DEFAULT_HISTORY_STORAGE: HistoryStorage | undefined =
typeof localStorage !== "undefined" ? localStorage : undefined;
/** /**
* Persists the SDS local history in a browser/localStorage compatible backend. * Persists the SDS local history in a browser/localStorage compatible backend.
@ -44,7 +46,7 @@ export class PersistentHistory implements ILocalHistory {
public constructor(options: PersistentHistoryOptions) { public constructor(options: PersistentHistoryOptions) {
this.memory = new MemLocalHistory(); this.memory = new MemLocalHistory();
this.storage = options.storage || localStorage; this.storage = options.storage ?? DEFAULT_HISTORY_STORAGE;
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.channelId}`; this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.channelId}`;
this.load(); this.load();
} }