FIX: Error in Ember CLI environment

There are a few fixes at play here:

1) We were still not initializing objects to the correct types.

2) If a debounce timed out, it was returning a string instead of an
array which was not appropriately handled.

3) In testing mode we never cancel the search promise for stability.
This commit is contained in:
Robin Ward 2021-09-07 14:44:06 -04:00
parent f4cca4af75
commit cddba50570
2 changed files with 13 additions and 10 deletions

View File

@ -20,12 +20,11 @@ function updateCache(term, results) {
function searchTags(term, categories, limit) { function searchTags(term, categories, limit) {
return new Promise((resolve) => { return new Promise((resolve) => {
const clearPromise = later( let clearPromise = isTesting()
() => { ? null
resolve(CANCELLED_STATUS); : later(() => {
}, resolve(CANCELLED_STATUS);
isTesting() ? 50 : 5000 }, 5000);
);
const debouncedSearch = (q, cats, resultFunc) => { const debouncedSearch = (q, cats, resultFunc) => {
discourseDebounce( discourseDebounce(

View File

@ -9,6 +9,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import { Promise } from "rsvp"; import { Promise } from "rsvp";
import { search as searchCategoryTag } from "discourse/lib/category-tag-search"; import { search as searchCategoryTag } from "discourse/lib/category-tag-search";
import userSearch from "discourse/lib/user-search"; import userSearch from "discourse/lib/user-search";
import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
const CATEGORY_SLUG_REGEXP = /(\#[a-zA-Z0-9\-:]*)$/gi; const CATEGORY_SLUG_REGEXP = /(\#[a-zA-Z0-9\-:]*)$/gi;
const USERNAME_REGEXP = /(\@[a-zA-Z0-9\-\_]*)$/gi; const USERNAME_REGEXP = /(\@[a-zA-Z0-9\-\_]*)$/gi;
@ -18,7 +19,7 @@ const searchData = {};
export function initSearchData() { export function initSearchData() {
searchData.loading = false; searchData.loading = false;
searchData.results = []; searchData.results = {};
searchData.noResults = false; searchData.noResults = false;
searchData.term = undefined; searchData.term = undefined;
searchData.typeFilter = null; searchData.typeFilter = null;
@ -52,8 +53,9 @@ const SearchHelper = {
if (matchSuggestions) { if (matchSuggestions) {
searchData.noResults = true; searchData.noResults = true;
searchData.results = []; searchData.results = {};
searchData.loading = false; searchData.loading = false;
searchData.suggestionResults = [];
if (matchSuggestions.type === "category") { if (matchSuggestions.type === "category") {
const categorySearchTerm = matchSuggestions.categoriesMatch[0].replace( const categorySearchTerm = matchSuggestions.categoriesMatch[0].replace(
@ -66,8 +68,10 @@ const SearchHelper = {
widget.siteSettings widget.siteSettings
); );
Promise.resolve(categoryTagSearch).then((results) => { Promise.resolve(categoryTagSearch).then((results) => {
searchData.suggestionResults = results; if (results !== CANCELLED_STATUS) {
searchData.suggestionKeyword = "#"; searchData.suggestionResults = results;
searchData.suggestionKeyword = "#";
}
widget.scheduleRerender(); widget.scheduleRerender();
}); });
} else if (matchSuggestions.type === "username") { } else if (matchSuggestions.type === "username") {