Skip to content

Instantly share code, notes, and snippets.

@jsnmoon
Created February 9, 2021 01:11
Show Gist options
  • Save jsnmoon/0367fcae2cdcd8f05780091d87575c97 to your computer and use it in GitHub Desktop.
Save jsnmoon/0367fcae2cdcd8f05780091d87575c97 to your computer and use it in GitHub Desktop.
diff --git a/projects/plugins/jetpack/modules/search/instant-search/components/search-app.jsx b/projects/plugins/jetpack/modules/search/instant-search/components/search-app.jsx
index 1b08ce5fa..470bafed0 100644
--- a/projects/plugins/jetpack/modules/search/instant-search/components/search-app.jsx
+++ b/projects/plugins/jetpack/modules/search/instant-search/components/search-app.jsx
@@ -69,12 +69,12 @@ class SearchApp extends Component {
}
componentDidUpdate( prevProps ) {
- if ( prevProps.searchQuery !== this.props.searchQuery ) {
- this.onChangeSearchQuery();
- }
-
- if ( prevProps.sort !== this.props.sort || prevProps.filters !== this.props.filters ) {
- this.onChangeSortOrFilters();
+ if (
+ prevProps.searchQuery !== this.props.searchQuery ||
+ prevProps.sort !== this.props.sort ||
+ prevProps.filters !== this.props.filters
+ ) {
+ this.onChangeQueryString();
}
}
@@ -219,11 +219,6 @@ class SearchApp extends Component {
showResults = () => {
this.setState( { showResults: true } );
this.preventBodyScroll();
-
- // If we've arrived via a filter or sort only, make sure the search query is set
- if ( this.props.searchQuery === null ) {
- this.props.setSearchQuery( '' );
- }
};
hideResults = () => {
@@ -234,23 +229,17 @@ class SearchApp extends Component {
} );
};
- onChangeSearchQuery = () => {
+ onChangeQueryString = () => {
this.getResults();
- if ( this.props.searchQuery !== null && ! this.state.showResults ) {
+ if ( this.hasActiveQuery() && ! this.state.showResults ) {
this.showResults();
}
- document.querySelectorAll( this.props.themeOptions.searchInputSelector ).forEach( input => {
- input.value = this.props.searchQuery;
- } );
- };
-
- onChangeSortOrFilters = () => {
- this.getResults();
-
- if ( this.hasActiveQuery() && ! this.state.showResults ) {
- this.showResults();
+ if ( this.props.searchQuery !== null ) {
+ document.querySelectorAll( this.props.themeOptions.searchInputSelector ).forEach( input => {
+ input.value = this.props.searchQuery;
+ } );
}
};
diff --git a/projects/plugins/jetpack/modules/search/instant-search/lib/api.js b/projects/plugins/jetpack/modules/search/instant-search/lib/api.js
index ace97f02b..416f072d7 100644
--- a/projects/plugins/jetpack/modules/search/instant-search/lib/api.js
+++ b/projects/plugins/jetpack/modules/search/instant-search/lib/api.js
@@ -196,6 +196,9 @@ function generateApiQueryString( {
postsPerPage = 10,
adminQueryFilter,
} ) {
+ if ( query === null ) {
+ query = '';
+ }
let fields = [
'date',
'permalink.url.raw',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment