da2089fb286b3119d62399a747a23fc22fa3ad70
chmalee
  Wed Mar 18 16:53:36 2026 -0700
Add plain position searches to the recents search stack on hgTracks/hgGateway, refs #34588

diff --git src/hg/js/autocompleteCat.js src/hg/js/autocompleteCat.js
index 6146fef979f..39a6c6e08f8 100644
--- src/hg/js/autocompleteCat.js
+++ src/hg/js/autocompleteCat.js
@@ -170,53 +170,57 @@
                     }
                 }
 
                 // Handle recent searches for position input
                 if (this.element[0].id === "positionInput" && request.term.length < 2) {
                     let searchStack = window.localStorage.getItem("searchStack");
                     if (request.term.length === 0 && searchStack) {
                         let searchObj = JSON.parse(searchStack);
                         let currDb = getDb();
                         if (currDb in searchObj) {
                             // sort the results list according to the stack order:
                             let entries = Object.entries(searchObj[currDb].results);
                             let stack = searchObj[currDb].stack;
                             let callbackData = [];
                             for (let s of stack) {
-                                callbackData.push(searchObj[currDb].results[s]);
+                                let item = searchObj[currDb].results[s];
+                                if (item && item.label) {
+                                    callbackData.push(item);
+                                }
                             }
                             acCallback(callbackData);
                         }
                         return;
                     }
                 } else if (request.term.length >=2) {
                     let results = cache[request.term];
                     if (results) {
                         acCallback(results);
                     } else if (options.baseUrl) {
                         doSearch(request.term, acCallback);
                     }
                 }
             };
 
             var autoCompleteSelect = function(event, ui) {
                 // This is a callback for autocomplete to let us know that the user selected
                 // a term from the list.  See http://api.jqueryui.com/autocomplete/#event-select
                 // since we are in an autocomplete don't bother saving the
                 // prefix the user typed in, just keep the geneSymbol itself
                 if (this.id === "positionInput") {
-                    addRecentSearch(getDb(), ui.item.geneSymbol, ui.item);
+                    let key = typeof(ui.item.geneSymbol) !== 'undefined' ? ui.item.geneSymbol : ui.item.value;
+                    addRecentSearch(getDb(), key, ui.item);
                 }
                 // Save genome selection for species search bars, but only if item has a definite db.
                 // Taxa-only selections (like "Human" without a specific db) are handled by the
                 // CGI's response handler after the actual db is determined.
                 if (options.showRecentGenomes && ui.item.db && !ui.item.disabled) {
                     if (ui.item.originalCategory) {
                         ui.item.category = ui.item.originalCategory;
                     }
                     addRecentGenome(ui.item);
                 }
                 if (typeof opts.onSelect === 'function') {
                     opts.onSelect(ui.item, $el);
                 }
                 $el.blur();
             };