Clicking a column header doesn't sort

2 views
Skip to first unread message

Marie-Jean THORAVAL

unread,
5:22 AM (7 hours ago) 5:22 AM
to zotero-dev
With the latest commits on GitHub, clicking a column header sometimes only moves the sort indicator without re-sorting the rows.

Steps to reproduce:
1) Have the items list sorted by the default column (e.g. Title), without that column having an explicit saved column-pref.
2) Click a different column header that does have a saved pref.
3) The sort caret moves to the clicked column, but the row order doesn't change.

Cause: _handleColumnSort (in itemTree.jsx) throws before it reaches await this.sort():
TypeError: can't access property "sortDirection",
columnSettings[this._sortedColumn.dataKey] is undefined


The guard checks one key but the delete accesses another:
if (columnSettings[column.dataKey]) {                          // checks the NEW column
    delete columnSettings[this._sortedColumn.dataKey].sortDirection;  // deletes from the OLD column
}


When the previously-sorted column has no entry in _getColumnPrefs(), columnSettings[this._sortedColumn.dataKey] is undefined and it throws.

This became reachable with commit 2ddb4e9 ("Show sort indicator on default-sorted column and fix first-click reverse"), which now sets this._sortedColumn to the default column in _getColumns() even before any header click. That default column often has no saved-pref entry, which is exactly the condition that trips the line above. (Before that commit, _sortedColumn was null on a default-sorted profile, so the block was skipped.)

Suggested fix — make the guard check the key it deletes:
- if (columnSettings[column.dataKey]) {
+ if (columnSettings[this._sortedColumn.dataKey]) {
      delete columnSettings[this._sortedColumn.dataKey].sortDirection;
  }


Verified on a local build — sorting works again after this change.
Happy to open a PR on GitHub if useful.


Reply all
Reply to author
Forward
0 new messages