From 9fa83a2a1c020ef3322f237b26733d88f2eeb6d9 Mon Sep 17 00:00:00 2001 From: Gigi Date: Wed, 22 Oct 2025 12:07:32 +0200 Subject: [PATCH] fix: ensure robust sorting of merged bookmarks with fallback timestamps --- src/services/bookmarkController.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/bookmarkController.ts b/src/services/bookmarkController.ts index 76c72fa1..68d081c8 100644 --- a/src/services/bookmarkController.ts +++ b/src/services/bookmarkController.ts @@ -347,8 +347,20 @@ class BookmarkController { })) const sortedBookmarks = enriched - .map(b => ({ ...b, urlReferences: extractUrlsFromContent(b.content) })) - .sort((a, b) => ((b.added_at || 0) - (a.added_at || 0)) || ((b.created_at || 0) - (a.created_at || 0))) + .map(b => ({ + ...b, + urlReferences: extractUrlsFromContent(b.content), + // Ensure we have valid timestamps for sorting + added_at: b.added_at || b.created_at || 0, + created_at: b.created_at || 0 + })) + .sort((a, b) => { + // Sort by added_at (when item was added to bookmark list), then by created_at + // Both should be newest first (descending) + const addedDiff = (b.added_at || 0) - (a.added_at || 0) + if (addedDiff !== 0) return addedDiff + return (b.created_at || 0) - (a.created_at || 0) + }) const bookmark: Bookmark = { id: `${activeAccount.pubkey}-bookmarks`,