diff --git a/js/historyView.js b/js/historyView.js index 8a4b6ef2..79840982 100644 --- a/js/historyView.js +++ b/js/historyView.js @@ -16,6 +16,7 @@ import { } from "./config.js"; import { getApplication } from "./applicationContext.js"; import { devLogger, userLogger } from "./utils/logger.js"; +import { logWatchHistoryDebug } from "./watchHistoryDebug.js"; import { normalizeVideoModerationContext, applyModerationContextDatasets, @@ -2321,6 +2322,13 @@ export function createWatchHistoryRenderer(config = {}) { }); } const feedItems = Array.isArray(result?.items) ? result.items : []; + logWatchHistoryDebug("watch-history:read", "info", "loadHistory result", { + force: force === true, + itemCount: feedItems.length, + values: feedItems + .map((entry) => entry?.pointer?.value || entry?.value) + .slice(0, 20), + }); const normalized = []; for (const entry of feedItems) { const pointer = normalizePointerInput(entry?.pointer || entry); diff --git a/js/ui/watchHistoryController.js b/js/ui/watchHistoryController.js index 2064d944..a6e35267 100644 --- a/js/ui/watchHistoryController.js +++ b/js/ui/watchHistoryController.js @@ -5,6 +5,7 @@ import { } from "../nostr/watchHistory.js"; import { normalizeDesignSystemContext } from "../designSystem.js"; import { devLogger } from "../utils/logger.js"; +import { logWatchHistoryDebug } from "../watchHistoryDebug.js"; const noop = () => {}; @@ -307,6 +308,15 @@ export default class WatchHistoryController { }); } + logWatchHistoryDebug("watch-history:remove", "info", "removal requested", { + removedPointerKey, + itemsSource: Array.isArray(payload.items) && payload.items.length + ? "renderer" + : "loadLatest", + remainingCount: normalizedItems.length, + remainingValues: normalizedItems.map((p) => p?.value).slice(0, 20), + }); + this.showSuccess("Removing from history…"); try { @@ -316,18 +326,33 @@ export default class WatchHistoryController { // Removal must replace the list, not merge the removed item back in. replace: true, }); + logWatchHistoryDebug("watch-history:remove", "info", "snapshot published", { + ok: snapshotResult?.ok, + empty: snapshotResult?.empty, + skipped: snapshotResult?.skipped, + }); try { - await this.nostrClient?.updateWatchHistoryList?.(normalizedItems, { - actorPubkey: actorCandidate || undefined, - replace: true, - source: reason, + const updateResult = await this.nostrClient?.updateWatchHistoryList?.( + normalizedItems, + { + actorPubkey: actorCandidate || undefined, + replace: true, + source: reason, + }, + ); + logWatchHistoryDebug("watch-history:remove", "info", "list update published", { + ok: updateResult?.ok, + finalItemCount: updateResult?.items?.length, }); } catch (updateError) { devLogger.warn( "[watchHistoryController] Failed to update local watch history list:", updateError, ); + logWatchHistoryDebug("watch-history:remove", "warn", "list update failed", { + error: updateError?.message || String(updateError), + }); } this.showSuccess( @@ -336,6 +361,11 @@ export default class WatchHistoryController { return { handledToasts: true, snapshot: snapshotResult }; } catch (error) { + logWatchHistoryDebug("watch-history:remove", "warn", "removal publish failed", { + error: error?.message || String(error), + retryable: error?.result?.retryable, + result: error?.result || null, + }); let message = "Failed to remove from history. Please try again."; if (error?.result?.retryable) { message = diff --git a/js/watchHistoryDebug.js b/js/watchHistoryDebug.js index 929be4d9..ed9ab91c 100644 --- a/js/watchHistoryDebug.js +++ b/js/watchHistoryDebug.js @@ -1,7 +1,5 @@ // js/watchHistoryDebug.js -import { devLogger } from "./utils/logger.js"; - const WATCH_HISTORY_DEBUG_STORAGE_KEY = "bitvid:debug:watch-history"; @@ -170,10 +168,19 @@ export function logWatchHistoryDebug(namespace, level, message, details) { return; } + // Route to console directly (not devLogger) so these opt-in diagnostics are + // visible in PRODUCTION builds too — the whole point of the flag is to debug + // issues on the hosted site, where devLogger is suppressed. + const consoleScope = + globalScope && globalScope.console ? globalScope.console : null; + const sink = consoleScope || (typeof console !== "undefined" ? console : null); + if (!sink) { + return; + } const methodName = - typeof level === "string" && level && typeof devLogger[level] === "function" + typeof level === "string" && level && typeof sink[level] === "function" ? level - : typeof devLogger.info === "function" + : typeof sink.info === "function" ? "info" : "log"; @@ -181,13 +188,13 @@ export function logWatchHistoryDebug(namespace, level, message, details) { try { if (details && typeof details === "object") { - devLogger[methodName](prefix, details); + sink[methodName](prefix, details); } else { - devLogger[methodName](prefix); + sink[methodName](prefix); } } catch (error) { - if (typeof devLogger.log === "function") { - devLogger.log(prefix); + if (typeof sink.log === "function") { + sink.log(prefix); } } }