Skip to content

Commit bf7ab9d

Browse files
committed
fix: respect DEFAULT_SETTINGS provider and use effective provider for URL writes
- useEffectiveSearchProvider falls back to DEFAULT_SETTINGS.searchProvider (not hardcoded 'algolia') so test env (default 'npm') no longer mismatches SSR vs hydration. - useGlobalSearch URL-write paths now use the effective provider so a ?p= override survives subsequent keystrokes/Enter.
1 parent e1466f8 commit bf7ab9d

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

app/composables/useGlobalSearch.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const SEARCH_DEBOUNCE_MS = 100
88

99
export function useGlobalSearch(place: 'header' | 'content' = 'content') {
1010
const { settings } = useSettings()
11-
const { searchProvider } = useSearchProvider()
1211
const searchProviderValue = useEffectiveSearchProvider()
1312

1413
const router = useRouter()
@@ -81,7 +80,7 @@ export function useGlobalSearch(place: 'header' | 'content' = 'content') {
8180
committedSearchQuery.value = searchQuery.value
8281
// When instant search is off the debounce queue is empty, so call directly
8382
if (!settings.value.instantSearch) {
84-
updateUrlQueryImpl(searchQuery.value, searchProvider.value)
83+
updateUrlQueryImpl(searchQuery.value, searchProviderValue.value)
8584
} else {
8685
updateUrlQuery.flush()
8786
}
@@ -98,9 +97,9 @@ export function useGlobalSearch(place: 'header' | 'content' = 'content') {
9897

9998
// Leading debounce implementation as it doesn't work properly out of the box (https://github.com/unjs/perfect-debounce/issues/43)
10099
if (!updateUrlQuery.isPending()) {
101-
updateUrlQueryImpl(value, searchProvider.value)
100+
updateUrlQueryImpl(value, searchProviderValue.value)
102101
}
103-
updateUrlQuery(value, searchProvider.value)
102+
updateUrlQuery(value, searchProviderValue.value)
104103
},
105104
})
106105

app/composables/useSettings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ export function useEffectiveSearchProvider() {
239239
const p = normalizeSearchParam(route.query.p)
240240
if (p === 'npm') return 'npm'
241241
if (p === 'algolia') return 'algolia'
242-
if (storedProviderReady.value && searchProvider.value === 'npm') return 'npm'
243-
return 'algolia'
242+
if (storedProviderReady.value) return searchProvider.value === 'npm' ? 'npm' : 'algolia'
243+
return DEFAULT_SETTINGS.searchProvider
244244
})
245245
}
246246

0 commit comments

Comments
 (0)