From b1fc6ac67cbb284f619a71cccb2e66c943147651 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 9 Mar 2017 03:04:41 -0500 Subject: [PATCH] Fix (some) crashes switching collections while items are being added The items list is generated from the database (via search), but new items may have been added to the database but not yet been registered, causing unloaded-data errors during sorting. Avoid that by not showing unregistered items when generating the items list. Additional protections are necessary -- it's still possible to get errors, and maybe a crash, if an item has been registered but not yet fully loaded -- but this addresses the most common one. --- chrome/content/zotero/xpcom/collectionTreeRow.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/chrome/content/zotero/xpcom/collectionTreeRow.js b/chrome/content/zotero/xpcom/collectionTreeRow.js index e61ac30d0..73cdbadf8 100644 --- a/chrome/content/zotero/xpcom/collectionTreeRow.js +++ b/chrome/content/zotero/xpcom/collectionTreeRow.js @@ -238,9 +238,21 @@ Zotero.CollectionTreeRow.prototype.getItems = Zotero.Promise.coroutine(function* } var ids = yield this.getSearchResults(); + + // Filter out items that exist in the items table (where search results come from) but that haven't + // yet been registered. This helps prevent unloaded-data crashes when switching collections while + // items are being added (e.g., during sync). + var len = ids.length; + ids = ids.filter(id => Zotero.Items.getLibraryAndKeyFromID(id)); + if (len > ids.length) { + let diff = len - ids.length; + Zotero.debug(`Not showing ${diff} unloaded item${diff != 1 ? 's' : ''}`); + } + if (!ids.length) { return [] } + return Zotero.Items.getAsync(ids); });