Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant Search: Use href to restore previous location state #13825

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion modules/search/class.jetpack-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ public function load_assets() {
'postTypeFilters' => $widget_options['post_types'],
'postTypes' => $post_type_labels,
'siteId' => Jetpack::get_option( 'id' ),
'siteUrl' => site_url(),
jeherve marked this conversation as resolved.
Show resolved Hide resolved
'sort' => $widget_options['sort'],
'widgets' => array_values( $widgets ),
);
Expand Down
4 changes: 2 additions & 2 deletions modules/search/instant-search/components/search-app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
setSortQuery,
getSortQuery,
hasFilter,
restorePreviousPath,
restorePreviousHref,
getSearchQuery,
} from '../lib/query-string';
import { removeChildren, hideElements, hideChildren, showChildren } from '../lib/dom';
Expand Down Expand Up @@ -97,7 +97,7 @@ class SearchApp extends Component {

this.setState( { showResults: false }, () => {
showChildren( this.props.themeOptions.resultsSelector );
restorePreviousPath( this.props.initialPath );
restorePreviousHref( this.props.initialHref );
} );
}

Expand Down
2 changes: 1 addition & 1 deletion modules/search/instant-search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const injectSearchApp = grabFocus => {
render(
<SearchApp
grabFocus={ grabFocus }
initialPath={ window[ SERVER_OBJECT_NAME ].siteUrl }
initialHref={ window.location.href }
initialSort={ determineDefaultSort( window[ SERVER_OBJECT_NAME ].sort, getSearchQuery() ) }
isSearchPage={ getSearchQuery() !== '' }
options={ window[ SERVER_OBJECT_NAME ] }
Expand Down
4 changes: 2 additions & 2 deletions modules/search/instant-search/lib/query-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function pushQueryString( queryString ) {
}
}

export function restorePreviousPath( newUrl ) {
export function restorePreviousHref( initialHref ) {
if ( history.pushState ) {
window.history.pushState( { path: newUrl }, '', newUrl );
window.history.pushState( { href: initialHref }, '', initialHref );
window.dispatchEvent( new Event( 'queryStringChange' ) );
}
}
Expand Down