Skip to content

Commit 4ac8b8e

Browse files
committed
Fix "Sorry, no guides matched your search." when starting initial search
1 parent dbb127c commit 4ac8b8e

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

assets/javascript/guides-app.js

+28-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ function debounce(wait, fn) {
1414
}
1515
}
1616

17+
function concat(fn1, fn2) {
18+
return function(...args) {
19+
fn1.apply(this, args)
20+
fn2.apply(this, args)
21+
}
22+
}
23+
1724
const appSelector = '#guides-app'
1825
const appElement = document.querySelector(appSelector);
1926

@@ -44,13 +51,21 @@ const app = createApp({
4451
},
4552
watch: {
4653
'search.input.q': {
47-
// "debounce" makes sure we only run search ~300ms after the user is done typing the text
48-
// WARNING: we really do want to debounce here, NOT in setters,
49-
// because debouncing in setters leads to data in input forms being refreshed after the timeout,
50-
// causing problems when typing text relatively fast.
51-
handler: debounce(300, function(newValue, oldValue) {
52-
this.resetAndSearch()
53-
})
54+
handler: concat(
55+
// Without debouncing, we want to cancel the previous search and mark the view as "loading",
56+
// so that we don't mistakenly display "no results" while debouncing the initial search.
57+
// See https://github.com/quarkusio/search.quarkus.io/issues/200
58+
function(newValue, oldValue) {
59+
this.resetAndMarkLoading()
60+
},
61+
// "debounce" makes sure we only run search ~300ms after the user is done typing the text
62+
// WARNING: we really do want to debounce here, NOT in setters,
63+
// because debouncing in setters leads to data in input forms being refreshed after the timeout,
64+
// causing problems when typing text relatively fast.
65+
debounce(300, function(newValue, oldValue) {
66+
this.resetAndSearch()
67+
})
68+
)
5469
},
5570
'search.input.categories': {
5671
handler(newValue, oldValue) {
@@ -161,6 +176,12 @@ const app = createApp({
161176
})
162177
},
163178
methods: {
179+
async resetAndMarkLoading() {
180+
if (this.loading) {
181+
this.loading.abort()
182+
}
183+
this.loading = new AbortController();
184+
},
164185
async resetAndSearch() {
165186
if (this.loading) {
166187
this.loading.abort()

0 commit comments

Comments
 (0)