Skip to content

Commit 7d0c8f0

Browse files
committed
special exception to search handling on Explorer page
1 parent 2a75862 commit 7d0c8f0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

javascripts/search.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ let $searchResultsContainer
77
let $searchOverlay
88
let $searchInput
99

10+
let isExplorerPage
11+
1012
// This is our default placeholder, but it can be localized with a <meta> tag
1113
let placeholder = 'Search topics, products...'
1214
let version
1315
let language
1416

1517
export default function search () {
18+
// We don't want to mess with query params intended for the GraphQL Explorer
19+
isExplorerPage = Boolean(document.getElementById('graphiql'))
20+
1621
// First, only initialize search if the elements are on the page
1722
$searchInputContainer = document.getElementById('search-input-container')
1823
$searchResultsContainer = document.getElementById('search-results-container')
@@ -51,7 +56,9 @@ export default function search () {
5156
searchWithYourKeyboard('#search-input-container input', '.ais-Hits-item')
5257

5358
// If the user already has a query in the URL, parse it and search away
54-
parseExistingSearch()
59+
if (!isExplorerPage) {
60+
parseExistingSearch()
61+
}
5562

5663
// If not on home page, decide if search panel should be open
5764
toggleSearchDisplay() // must come after parseExistingSearch
@@ -133,8 +140,9 @@ async function onSearch () {
133140
const query = $searchInput.value
134141

135142
// Update the URL with the search parameters in the query string
143+
// UNLESS this is the GraphQL Explorer page, where a query in the URL is a GraphQL query
136144
const pushUrl = new URL(location)
137-
pushUrl.search = query ? new URLSearchParams({ query }) : ''
145+
pushUrl.search = query && !isExplorerPage ? new URLSearchParams({ query }) : ''
138146
history.pushState({}, '', pushUrl)
139147

140148
// If there's a query, call the endpoint

0 commit comments

Comments
 (0)