From cc66fafcdda9bab64fba00f86c9f2c3f8902dfd0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 18 Jan 2026 04:49:07 +0000 Subject: [PATCH] fix(hashtag-preferences): prevent crash and data loss on load failure - fix `TypeError: Assignment to constant variable` in `HashtagPreferencesService.load` by changing `const` to `let` for `wasLoadedForUser`. - Prevent existing cached preferences from being wiped when remote decryption fails. --- js/services/hashtagPreferencesService.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/services/hashtagPreferencesService.js b/js/services/hashtagPreferencesService.js index dd8a8851..4816d877 100644 --- a/js/services/hashtagPreferencesService.js +++ b/js/services/hashtagPreferencesService.js @@ -414,7 +414,7 @@ class HashtagPreferencesService { async load(pubkey) { const normalized = normalizeHexPubkey(pubkey); - const wasLoadedForUser = + let wasLoadedForUser = this.activePubkey && this.activePubkey === normalized && (this.interests.size > 0 || this.disinterests.size > 0 || this.loaded); @@ -573,9 +573,16 @@ class HashtagPreferencesService { `${LOG_PREFIX} Failed to decrypt hashtag preferences`, decryptResult.error, ); - // If decryption fails on a reload, we might want to keep old data? - // But typically decryption failure means key mismatch or bad payload. - // Resetting is safer here to avoid stuck state, unless we want to be very conservative. + + // If we already have loaded preferences (e.g. from cache), preserve them + // rather than wiping everything just because the remote update couldn't be decrypted. + if (wasLoadedForUser) { + userLogger.warn( + `${LOG_PREFIX} Preserving cached preferences despite decryption failure.`, + ); + return; + } + this.reset(); this.loaded = true; return;