@@ -15,12 +15,13 @@ const emit = defineEmits(['blur', 'focus'])
1515
1616const router = useRouter ()
1717const route = useRoute ()
18+ const { searchProvider } = useSearchProvider ()
1819// The actual search provider (from URL, used for API calls)
1920const searchProviderParam = computed (() => {
2021 const p = normalizeSearchParam (route .query .p )
22+ if (! p && searchProvider .value === ' npm' ) return ' npm'
2123 return p === ' npm' ? ' npm' : ' algolia'
2224})
23- const { searchProvider } = useSearchProvider ()
2425const searchProviderValue = computed (() => searchProviderParam .value || searchProvider .value )
2526
2627const isSearchFocused = shallowRef (false )
@@ -35,15 +36,13 @@ const searchQuery = shallowRef(normalizeSearchParam(route.query.q))
3536// Pages that have their own local filter using ?q
3637const pagesWithLocalFilter = new Set ([' ~username' , ' org' ])
3738
38- function updateUrlQueryImpl(value : string ) {
39+ function updateUrlQueryImpl(value : string , provider : ' npm ' | ' algolia ' ) {
3940 // Don't navigate away from pages that use ?q for local filtering
4041 if (pagesWithLocalFilter .has (route .name as string )) {
4142 return
4243 }
4344 if (route .name === ' search' ) {
44- router .replace ({
45- query: { q: value || undefined , p: searchProviderValue .value === ' npm' ? ' npm' : undefined },
46- })
45+ router .replace ({ query: { q: value || undefined , p: provider === ' npm' ? ' npm' : undefined } })
4746 return
4847 }
4948 if (! value ) {
@@ -54,7 +53,7 @@ function updateUrlQueryImpl(value: string) {
5453 name: ' search' ,
5554 query: {
5655 q: value ,
57- p: searchProviderValue . value === ' npm' ? ' npm' : undefined ,
56+ p: provider === ' npm' ? ' npm' : undefined ,
5857 },
5958 })
6059}
@@ -64,7 +63,10 @@ const updateUrlQueryAlgolia = debounce(updateUrlQueryImpl, 80)
6463
6564const updateUrlQuery = Object .assign (
6665 (value : string ) =>
67- (searchProviderValue .value === ' algolia' ? updateUrlQueryAlgolia : updateUrlQueryNpm )(value ),
66+ (searchProviderValue .value === ' algolia' ? updateUrlQueryAlgolia : updateUrlQueryNpm )(
67+ value ,
68+ searchProviderValue .value ,
69+ ),
6870 {
6971 flush : () =>
7072 (searchProviderValue .value === ' algolia' ? updateUrlQueryAlgolia : updateUrlQueryNpm ).flush (),
@@ -96,7 +98,7 @@ function handleSubmit() {
9698 name: ' search' ,
9799 query: {
98100 q: searchQuery .value ,
99- p: searchProviderValue .value ,
101+ p: searchProviderValue .value === ' npm ' ? ' npm ' : undefined ,
100102 },
101103 })
102104 } else {
0 commit comments