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 15f1a22f2e
commit 581430ab43
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 DEFAULT_HISTORY_STORAGE: HistoryStorage | undefined =
typeof localStorage !== "undefined" ? localStorage : undefined;
/**
* Persists the SDS local history in a browser/localStorage compatible backend.
@ -44,7 +46,7 @@ export class PersistentHistory implements ILocalHistory {
public constructor(options: PersistentHistoryOptions) {
this.memory = new MemLocalHistory();
this.storage = options.storage || localStorage;
this.storage = options.storage ?? DEFAULT_HISTORY_STORAGE;
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.channelId}`;
this.load();
}