diff --git a/framework/core/js/src/forum/components/Search.tsx b/framework/core/js/src/forum/components/Search.tsx index 645fa9241..054c0b307 100644 --- a/framework/core/js/src/forum/components/Search.tsx +++ b/framework/core/js/src/forum/components/Search.tsx @@ -88,7 +88,7 @@ export default class Search extends Compone /** * An array of SearchSources. */ - protected sources!: SearchSource[]; + protected sources?: SearchSource[]; /** * The number of sources that are still loading results. @@ -192,7 +192,7 @@ export default class Search extends Compone this.setIndex(this.getCurrentNumericIndex()); // If there are no sources, the search view is not shown. - if (!this.sources.length) return; + if (!this.sources?.length) return; this.updateMaxHeight(); } @@ -200,6 +200,10 @@ export default class Search extends Compone oncreate(vnode: Mithril.VnodeDOM) { super.oncreate(vnode); + // If there are no sources, we shouldn't initialize logic for + // search elements, as they will not be shown. + if (!this.sources?.length) return; + const search = this; const state = this.searchState; @@ -237,7 +241,7 @@ export default class Search extends Compone if (state.isCached(query)) return; if (query.length >= (search.constructor as typeof Search).MIN_SEARCH_LEN) { - search.sources.map((source) => { + search.sources?.map((source) => { if (!source.search) return; search.loadingSources++;