Skip to content

Commit 4c8fe76

Browse files
feat: reduce watchers and timeouts
1 parent 2d169fe commit 4c8fe76

File tree

3 files changed

+10
-40
lines changed

3 files changed

+10
-40
lines changed

app/components/AppHeader.vue

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,12 @@ function expandMobileSearch() {
3333
})
3434
}
3535
36-
watch(
37-
isOnSearchPage,
38-
visible => {
39-
if (!visible) return
40-
41-
searchBoxRef.value?.focus()
42-
nextTick(() => {
43-
searchBoxRef.value?.focus()
44-
})
45-
},
46-
{ flush: 'sync' },
47-
)
48-
4936
function handleSearchBlur() {
5037
showFullSearch.value = false
51-
// Collapse expanded search on mobile after blur (with delay for click handling)
38+
// Collapse expanded search on mobile after blur
5239
// But don't collapse if we're on the search page
5340
if (isMobile.value && !isOnSearchPage.value) {
54-
setTimeout(() => {
55-
isSearchExpandedManually.value = false
56-
}, 150)
41+
isSearchExpandedManually.value = false
5742
}
5843
}
5944

app/components/Header/SearchBox.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ const emit = defineEmits(['blur', 'focus'])
1616
const router = useRouter()
1717
const route = useRoute()
1818
19-
const isSearchFocused = shallowRef(false)
20-
2119
const showSearchBar = computed(() => {
2220
return route.name !== 'index'
2321
})
2422
2523
// Local input value (updates immediately as user types)
26-
const searchQuery = shallowRef(normalizeSearchParam(route.query.q))
24+
const searchQuery = shallowRef('')
2725
2826
// Pages that have their own local filter using ?q
2927
const pagesWithLocalFilter = new Set(['~username', 'org'])
@@ -50,11 +48,6 @@ const updateUrlQuery = debounce((value: string) => {
5048
})
5149
}, 250)
5250
53-
// Watch input and debounce URL updates
54-
watch(searchQuery, value => {
55-
updateUrlQuery(value)
56-
})
57-
5851
// Sync input with URL when navigating (e.g., back button)
5952
watch(
6053
() => route.query.q,
@@ -68,14 +61,18 @@ watch(
6861
searchQuery.value = value
6962
}
7063
},
64+
{ immediate: true },
7165
)
7266
67+
// Watch input and debounce URL updates
68+
watch(searchQuery, value => {
69+
updateUrlQuery(value)
70+
})
71+
7372
function handleSearchBlur() {
74-
isSearchFocused.value = false
7573
emit('blur')
7674
}
7775
function handleSearchFocus() {
78-
isSearchFocused.value = true
7976
emit('focus')
8077
}
8178
@@ -106,7 +103,7 @@ defineExpose({ focus })
106103
{{ $t('search.label') }}
107104
</label>
108105

109-
<div class="relative group" :class="{ 'is-focused': isSearchFocused }">
106+
<div class="relative group">
110107
<div class="search-box relative flex items-center">
111108
<span
112109
class="absolute inset-is-3 text-fg-subtle font-mono text-sm pointer-events-none transition-colors duration-200 motion-reduce:transition-none [.group:hover:not(:focus-within)_&]:text-fg/80 group-focus-within:text-accent z-1"

app/pages/search.vue

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ const updateUrlPage = debounce((page: number) => {
3232
// The actual search query (from URL, used for API calls)
3333
const query = computed(() => normalizeSearchParam(route.query.q))
3434
35-
// Track if page just loaded (for hiding "Searching..." during view transition)
36-
const hasInteracted = shallowRef(false)
37-
onMounted(() => {
38-
// Small delay to let view transition complete
39-
setTimeout(() => {
40-
hasInteracted.value = true
41-
}, 300)
42-
})
43-
4435
// Infinite scroll / pagination state
4536
const pageSize = 25
4637
const currentPage = shallowRef(1)
@@ -168,8 +159,6 @@ function handleClearFilter(chip: FilterChip) {
168159
169160
// Should we show the loading spinner?
170161
const showSearching = computed(() => {
171-
// Don't show during initial page load (view transition)
172-
if (!hasInteracted.value) return false
173162
// Show if pending and no results yet
174163
return status.value === 'pending' && displayResults.value.length === 0
175164
})
@@ -190,7 +179,6 @@ function handlePageChange(page: number) {
190179
// Reset page when query changes
191180
watch(query, () => {
192181
currentPage.value = 1
193-
hasInteracted.value = true
194182
})
195183
196184
// Check if current query could be a valid package name

0 commit comments

Comments
 (0)