@@ -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+
1724const appSelector = '#guides-app'
1825const 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,11 +176,14 @@ const app = createApp({
161176 } )
162177 } ,
163178 methods : {
164- async resetAndSearch ( ) {
179+ async resetAndMarkLoading ( ) {
165180 if ( this . loading ) {
166181 this . loading . abort ( )
167182 }
168- this . loading = new AbortController ( ) ;
183+ this . loading = new AbortController ( )
184+ } ,
185+ async resetAndSearch ( ) {
186+ resetAndMarkLoading ( )
169187 this . _resetResults ( )
170188 await this . _searchBatch ( this . initialTimeout )
171189 } ,
0 commit comments