From 0042d94f76ccb6a4e265c272fc9c20985861f818 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 7 May 2018 17:48:25 +0800 Subject: [PATCH] Fix broken JS specs. --- .../javascripts/discourse/widgets/search-menu.js.es6 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/search-menu.js.es6 b/app/assets/javascripts/discourse/widgets/search-menu.js.es6 index 4b8d5c17727..ac0ea6a68c2 100644 --- a/app/assets/javascripts/discourse/widgets/search-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/search-menu.js.es6 @@ -66,7 +66,7 @@ const SearchHelper = { searchData.results = content; - if (searchContext.type === 'topic') { + if (searchContext && searchContext.type === 'topic') { widget.appEvents.trigger('post-stream:refresh', { force: true }); searchData.topicId = searchContext.id; } @@ -170,10 +170,15 @@ export default createWidget('search-menu', { html(attrs) { searchData.contextEnabled = attrs.contextEnabled; + const searchContext = this.searchContext(); const shouldTriggerSearch = ( (searchData.contextEnabled !== attrs.contextEnabled) || - (this.searchContext().type === 'topic' && searchData.topicId !== this.searchContext().id) + (searchContext && + searchContext.type === 'topic' && + searchData.topicId !== null && + searchData.topicId !== searchContext.id + ) ); if (shouldTriggerSearch && searchData.term) {