Skip to content

Commit d4a3281

Browse files
Revert "refactor: optimize search on update"
This reverts commit 29a84e2.
1 parent 29a84e2 commit d4a3281

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

app/components/AppHeader.vue

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script setup lang="ts">
2-
import { debounce } from 'perfect-debounce'
32
import { isEditableElement } from '~/utils/input'
43
54
withDefaults(
@@ -17,31 +16,30 @@ const showFullSearch = shallowRef(false)
1716
const showMobileMenu = shallowRef(false)
1817
1918
// On mobile, clicking logo+search button expands search
19+
const route = useRoute()
2020
const isMobile = useIsMobile()
2121
const isSearchExpandedManually = shallowRef(false)
2222
const searchBoxRef = useTemplateRef('searchBoxRef')
2323
24-
const route = useRoute()
25-
const searchQuery = shallowRef<string>(normalizeSearchParam(route.query.q))
26-
24+
const searchQuery = shallowRef('')
2725
watch(
2826
() => route.query.q,
2927
queryValue => {
30-
if (queryValue !== searchQuery.value) {
31-
searchQuery.value = normalizeSearchParam(queryValue)
32-
}
28+
searchQuery.value = normalizeSearchParam(queryValue)
3329
},
30+
{ immediate: true },
3431
)
3532
36-
const router = useRouter()
37-
const onSearchQueryUpdate = debounce((newSearchQuery: string) => {
38-
if (newSearchQuery !== searchQuery.value) {
39-
router.replace({
40-
name: 'search',
41-
query: { q: newSearchQuery === '' ? undefined : newSearchQuery },
42-
})
33+
async function handleSearchSubmit() {
34+
if (!searchQuery.value) {
35+
return
4336
}
44-
}, 500)
37+
38+
await navigateTo({
39+
name: 'search',
40+
query: { q: searchQuery.value },
41+
})
42+
}
4543
4644
// On search page, always show search expanded on mobile
4745
const isOnHomePage = computed(() => route.name === 'index')
@@ -149,8 +147,8 @@ onKeyStroke(
149147
ref="searchBoxRef"
150148
class="max-w-sm"
151149
compact
152-
:model-value="searchQuery"
153-
@update:model-value="onSearchQueryUpdate"
150+
v-model="searchQuery"
151+
@submit="handleSearchSubmit"
154152
@focus="handleSearchFocus"
155153
@blur="handleSearchBlur"
156154
/>

app/pages/search.vue

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -573,24 +573,6 @@ watch(displayResults, results => {
573573
})
574574
575575
function handleResultsKeydown(e: KeyboardEvent) {
576-
// If the active element is an input, navigate to exact match or wait for results
577-
if (e.key === 'Enter' && document.activeElement?.tagName === 'INPUT') {
578-
// Get value directly from input (not from route query, which may be debounced)
579-
const inputValue = (document.activeElement as HTMLInputElement).value.trim()
580-
if (!inputValue) return
581-
582-
// Check if first result matches the input value exactly
583-
const firstResult = displayResults.value[0]
584-
if (firstResult?.package.name === inputValue) {
585-
pendingEnterQuery.value = null
586-
return navigateToPackage(firstResult.package.name)
587-
}
588-
589-
// No match yet - store input value, watcher will handle navigation when results arrive
590-
pendingEnterQuery.value = inputValue
591-
return
592-
}
593-
594576
if (totalSelectableCount.value <= 0) return
595577
596578
const elements = getFocusableElements()

0 commit comments

Comments
 (0)