@@ -14,6 +14,13 @@ function debounce(wait, fn) {
14
14
}
15
15
}
16
16
17
+ function concat ( fn1 , fn2 ) {
18
+ return function ( ...args ) {
19
+ fn1 . apply ( this , args )
20
+ fn2 . apply ( this , args )
21
+ }
22
+ }
23
+
17
24
const appSelector = '#guides-app'
18
25
const appElement = document . querySelector ( appSelector ) ;
19
26
@@ -44,13 +51,21 @@ const app = createApp({
44
51
} ,
45
52
watch : {
46
53
'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
+ )
54
69
} ,
55
70
'search.input.categories' : {
56
71
handler ( newValue , oldValue ) {
@@ -161,11 +176,14 @@ const app = createApp({
161
176
} )
162
177
} ,
163
178
methods : {
164
- async resetAndSearch ( ) {
179
+ async resetAndMarkLoading ( ) {
165
180
if ( this . loading ) {
166
181
this . loading . abort ( )
167
182
}
168
- this . loading = new AbortController ( ) ;
183
+ this . loading = new AbortController ( )
184
+ } ,
185
+ async resetAndSearch ( ) {
186
+ resetAndMarkLoading ( )
169
187
this . _resetResults ( )
170
188
await this . _searchBatch ( this . initialTimeout )
171
189
} ,
0 commit comments