@@ -135,7 +135,7 @@ <h1>Moss <span>Playground</span></h1>
135135</ div >
136136
137137< script type ="module ">
138- const mossToken = document . querySelector ( 'meta[name="moss-token"]' ) ?. getAttribute ( 'content ') || '' ;
138+ const mossToken = location . hash . replace ( / ^ # / , ' ') || '' ;
139139
140140function apiFetch ( path , options = { } ) {
141141 const headers = { ...options . headers , 'X-Moss-Token' : mossToken } ;
@@ -227,6 +227,9 @@ <h1>Moss <span>Playground</span></h1>
227227 const name = select . value ;
228228 if ( ! name ) return ;
229229
230+ ++ requestId ;
231+ if ( searchTimeout ) clearTimeout ( searchTimeout ) ;
232+
230233 loadBtn . disabled = true ;
231234 loadBtn . innerHTML = '<span class="spinner">◠</span> Loading...' ;
232235 loadStatus . classList . remove ( 'hidden' ) ;
@@ -344,6 +347,7 @@ <h1>Moss <span>Playground</span></h1>
344347
345348 if ( searchTimeout ) clearTimeout ( searchTimeout ) ;
346349 const thisRequestId = ++ requestId ;
350+ const idx = currentIndex ;
347351 searchTimeout = setTimeout ( async ( ) => {
348352 const placeholder = results . querySelector ( '.empty-state' ) ;
349353 if ( placeholder ) placeholder . innerHTML = '<p>Searching...</p>' ;
@@ -352,7 +356,7 @@ <h1>Moss <span>Playground</span></h1>
352356 const res = await apiFetch ( '/api/query' , {
353357 method : 'POST' ,
354358 headers : { 'Content-Type' : 'application/json' } ,
355- body : JSON . stringify ( { name : currentIndex , query, topK, alpha } ) ,
359+ body : JSON . stringify ( { name : idx , query, topK, alpha } ) ,
356360 } ) ;
357361 if ( ! res . ok ) {
358362 const err = await res . json ( ) ;
@@ -370,6 +374,8 @@ <h1>Moss <span>Playground</span></h1>
370374}
371375
372376select . addEventListener ( 'change' , ( ) => {
377+ ++ requestId ;
378+ if ( searchTimeout ) clearTimeout ( searchTimeout ) ;
373379 updateLoadBtn ( ) ;
374380 const name = select . value ;
375381 const idx = indexes . find ( i => i . name === name ) ;
0 commit comments