Bug at collectionViewItemTree.js:937 (Duplicate row shown for newly added item)

When I add a new item in Zotero 10.0.9 (ARM64, macOS 27.2.1) while my library is sorted descending by Date Modified, the newly added item can appear twice in the item tree even though only one item exists in the database. Deleting either of the two visible rows deletes the single underlying item.

I traced the duplicate row to a falsy-zero check in chrome/content/zotero/collectionViewItemTree.js on line 937:
    if (type == 'item' && action == 'add') {
if (!items) items = Zotero.Items.get(ids);
for (let item of items) {
// if the item belongs in one of the selected views
if ((collectionTreeRows.some((row) => row.isLibrary(true) && row.ref.libraryID == item.libraryID) ||
collectionTreeRows.some((row) => row.isCollection() && item.inCollection(row.ref.id))
// if we haven't already added it to our hash map
) && !this._rowMap[item.id]
// Regular item or standalone note/attachment
&& item.isTopLevelItem()) {
let beforeRow = this.getRowCount();
this._addRow(this.createRow(item, 0, false), beforeRow);
madeChanges = true;
}
}
If an item-tree refresh runs before CollectionViewItemTree.notify('add', 'item', ...) executes, the newly added item is already in this._rowMap. Because the list is sorted descending by Date Modified, the newly added item sits at row index 0, so this._rowMap[item.id] equals 0. The check !this._rowMap[item.id] evaluates to true for 0, so Zotero calls this._addRow(...) a second time and logs the following warnings:
(2)(+0000002): WARNING: refreshRowMap(): item row 0 already found for item 86035 at 8475
(2)(+0000000): refreshRowMap@chrome://zotero/content/itemTree.js:481:22 _addRow@chrome://zotero/content/itemTree.js:491:12 notify@chrome://zotero/content/collectionViewItemTree.js:941:16
...
(3)(+0000000): Sorting items list by dateModified, firstCreator, date, title, dateAdded descending
(2)(+0000063): WARNING: refreshRowMap(): item row 0 already found for item 86035 at 1
(2)(+0000000): refreshRowMap@chrome://zotero/content/itemTree.js:481:22 _sort@chrome://zotero/content/itemTree.js:829:10 _sort@chrome://zotero/content/collectionViewItemTree.js:189:11 notify@chrome://zotero/content/collectionViewItemTree.js:990:12
Changing !this._rowMap[item.id] on line 937 to this._rowMap[item.id] === undefined (or !(item.id in this._rowMap)) should prevent Zotero from adding a duplicate row when the existing row index is 0.

In my setup, Scite Zotero Plugin (2.0.5) triggers this race condition because it registers an item observer at priority 1 (ahead of itemTreeView at priority 50) and calls Zotero.Notifier.trigger('refresh', 'itemtree', []) when tallies arrive for a new DOI. I am reporting that plugin-side issue to Scite separately, and I am reporting the falsy-zero guard bug here because any refresh that places a newly added item at row 0 before notify('add', 'item', ...) runs will hit line 937 in Zotero core.

I have emailed a trimmed, redacted debug log excerpt covering this event to support@zotero.org with a link to this thread.
Sign In or Register to comment.