@@ -7,6 +7,7 @@ import { useTranslation } from 'components/hooks/useTranslation'
77import { sendEvent , EventType } from 'components/lib/events'
88import { useMainContext } from './context/MainContext'
99import { useVersion } from 'components/hooks/useVersion'
10+ import { useQuery } from 'components/hooks/useQuery'
1011import { useLanguages } from './context/LanguagesContext'
1112
1213import styles from './Search.module.scss'
@@ -36,10 +37,7 @@ export function Search({
3637 children,
3738} : Props ) {
3839 const router = useRouter ( )
39- const query =
40- router . query . query && Array . isArray ( router . query . query )
41- ? router . query . query [ 0 ]
42- : router . query . query || ''
40+ const { query, debug } = useQuery ( )
4341 const [ localQuery , setLocalQuery ] = useState ( query )
4442 const [ debouncedQuery , setDebouncedQuery ] = useDebounce < string > ( localQuery , 300 )
4543 const inputRef = useRef < HTMLInputElement > ( null )
@@ -185,7 +183,7 @@ export function Search({
185183 isLoading = { isLoading }
186184 results = { previousResults }
187185 closeSearch = { closeSearch }
188- debug = { ' debug' in router . query }
186+ debug = { debug }
189187 query = { query }
190188 />
191189 </ div >
@@ -279,7 +277,7 @@ function ShowSearchResults({
279277 results : SearchResult [ ] | undefined
280278 closeSearch : ( ) => void
281279 debug : boolean
282- query : string | string [ ]
280+ query : string
283281} ) {
284282 const { t } = useTranslation ( 'search' )
285283 const router = useRouter ( )
@@ -298,7 +296,13 @@ function ShowSearchResults({
298296 version : version ,
299297 }
300298 } )
301- const redirectQuery = query ? `?query=${ query } ` : ''
299+
300+ const redirectParams : {
301+ query : string
302+ debug ?: string
303+ } = { query }
304+ if ( debug ) redirectParams . debug = JSON . stringify ( debug )
305+ const redirectQuery = `?${ new URLSearchParams ( redirectParams ) . toString ( ) } `
302306
303307 if ( results ) {
304308 if ( results . length === 0 ) {
@@ -350,7 +354,7 @@ function ShowSearchResults({
350354 renderItem : ( ) => (
351355 < ActionList . Item as = "div" >
352356 < Link href = { url } className = "no-underline color-fg-default" >
353- < li key = { url } data-testid = "search-result" className = { cx ( 'list-style-none' ) } >
357+ < li data-testid = "search-result" className = { cx ( 'list-style-none' ) } >
354358 < div className = { cx ( 'py-2 px-3' ) } >
355359 { /* Breadcrumbs in search records don't include the page title. These fields may contain <mark> elements that we need to render */ }
356360 < Label variant = "small" sx = { { bg : 'accent.emphasis' } } >
0 commit comments